mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
* 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
// Package b14coder base16384 与 tea 加解密
|
|
package b14coder
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
control "github.com/FloatTech/zbputils/control"
|
|
base14 "github.com/fumiama/go-base16384"
|
|
tea "github.com/fumiama/gofastTEA"
|
|
zero "github.com/wdvxdr1123/ZeroBot"
|
|
"github.com/wdvxdr1123/ZeroBot/message"
|
|
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
|
|
|
"github.com/FloatTech/ZeroBot-Plugin/order"
|
|
)
|
|
|
|
func init() {
|
|
en := control.Register("base16384", order.PrioBase14, &control.Options{
|
|
DisableOnDefault: false,
|
|
Help: "base16384加解密\n" +
|
|
"- 加密xxx\n- 解密xxx\n- 用yyy加密xxx\n- 用yyy解密xxx",
|
|
})
|
|
en.OnRegex(`^加密\s?(.*)`).SetBlock(true).
|
|
Handle(func(ctx *zero.Ctx) {
|
|
str := ctx.State["regex_matched"].([]string)[1]
|
|
es, err := base14.UTF16be2utf8(base14.EncodeString(str))
|
|
if err == nil {
|
|
ctx.SendChain(message.Text(helper.BytesToString(es)))
|
|
} else {
|
|
ctx.SendChain(message.Text("加密失败!"))
|
|
}
|
|
})
|
|
en.OnRegex(`^解密\s?([一-踀]*[㴁-㴆]?)$`).SetBlock(true).
|
|
Handle(func(ctx *zero.Ctx) {
|
|
str := ctx.State["regex_matched"].([]string)[1]
|
|
es, err := base14.UTF82utf16be(helper.StringToBytes(str))
|
|
if err == nil {
|
|
ctx.SendChain(message.Text(base14.DecodeString(es)))
|
|
} else {
|
|
ctx.SendChain(message.Text("解密失败!"))
|
|
}
|
|
})
|
|
en.OnRegex(`^用(.*)加密\s?(.*)`).SetBlock(true).
|
|
Handle(func(ctx *zero.Ctx) {
|
|
key, str := ctx.State["regex_matched"].([]string)[1], ctx.State["regex_matched"].([]string)[2]
|
|
t := getea(key)
|
|
es, err := base14.UTF16be2utf8(base14.Encode(t.Encrypt(helper.StringToBytes(str))))
|
|
if err == nil {
|
|
ctx.SendChain(message.Text(helper.BytesToString(es)))
|
|
} else {
|
|
ctx.SendChain(message.Text("加密失败!"))
|
|
}
|
|
})
|
|
en.OnRegex(`^用(.*)解密\s?([一-踀]*[㴁-㴆]?)$`).SetBlock(true).
|
|
Handle(func(ctx *zero.Ctx) {
|
|
key, str := ctx.State["regex_matched"].([]string)[1], ctx.State["regex_matched"].([]string)[2]
|
|
t := getea(key)
|
|
es, err := base14.UTF82utf16be(helper.StringToBytes(str))
|
|
if err == nil {
|
|
ctx.SendChain(message.Text(helper.BytesToString(t.Decrypt(base14.Decode(es)))))
|
|
} else {
|
|
ctx.SendChain(message.Text("解密失败!"))
|
|
}
|
|
})
|
|
}
|
|
|
|
func getea(key string) tea.TEA {
|
|
kr := []rune(key)
|
|
if len(kr) > 4 {
|
|
kr = kr[:4]
|
|
} else {
|
|
for len(kr) < 4 {
|
|
kr = append(kr, rune(4-len(kr)))
|
|
}
|
|
}
|
|
return *(*tea.TEA)(*(*unsafe.Pointer)(unsafe.Pointer(&kr)))
|
|
}
|