feat(crypter): 添加qq表情加密并支持回应密文 (#1287)

This commit is contained in:
Kajiekazz
2026-02-19 23:46:33 +08:00
committed by GitHub
parent 82dc709f3b
commit e0fa3ba0b3
4 changed files with 213 additions and 17 deletions

66
plugin/crypter/qqemoji.go Normal file
View File

@@ -0,0 +1,66 @@
// Package crypter QQ表情加解密
package crypter
import (
"fmt"
"strings"
"unicode/utf8"
"github.com/wdvxdr1123/ZeroBot/message"
)
const (
emojiZeroID = 297
emojiOneID = 424
)
func encodeQQEmoji(text string) message.Message {
if text == "" {
return message.Message{message.Text("请输入要加密的文本")}
}
var bin strings.Builder
for _, b := range []byte(text) {
fmt.Fprintf(&bin, "%08b", b)
}
s := bin.String()
msg := make(message.Message, 0, len(s))
for _, bit := range s {
if bit == '0' {
msg = append(msg, message.Face(emojiZeroID))
} else {
msg = append(msg, message.Face(emojiOneID))
}
}
return msg
}
func decodeQQEmoji(faceIDs []int) string {
var bin strings.Builder
for _, id := range faceIDs {
if id == emojiZeroID {
bin.WriteByte('0')
} else if id == emojiOneID {
bin.WriteByte('1')
}
}
binary := bin.String()
if len(binary) == 0 || len(binary)%8 != 0 {
return "QQ表情密文格式错误"
}
data := make([]byte, len(binary)/8)
for i := range data {
for j := 0; j < 8; j++ {
if binary[i*8+j] == '1' {
data[i] |= 1 << (7 - j)
}
}
}
if !utf8.Valid(data) {
return "QQ表情解密失败结果不是有效文本"
}
return string(data)
}