diff --git a/.gitignore b/.gitignore index abeea788..aa881c53 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ data/control data/SetuTime/search data/manager data/acgimage +data/saucenao data/fortune data/hs plugins/*.so diff --git a/README.md b/README.md index f1fb6e99..5d5e5098 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ zerobot -h -t token -u url [-d|w] [-g] qq1 qq2 qq3 ... - [x] /还原 xxx (在发送的群/用户还原xxx的开启状态到初始状态) - [x] /用法 xxx - [x] /服务列表 + - [x] @Bot 插件冲突检测 (会在本群发送一条消息并在约 1s 后撤回以检测其它同类 bot 中已启用的插件并禁用) - **聊天** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chat"` - [x] [BOT名字] - [x] [戳一戳BOT] @@ -108,6 +109,9 @@ zerobot -h -t token -u url [-d|w] [-g] qq1 qq2 qq3 ... - [x] 摸[@xxx] - [x] 搓[@xxx] - 注:更多指令见项目 --> https://github.com/tdf1939/ZeroBot-Plugin-Gif +- **base16384加解密** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_b14"` + - [x] 加密xxx + - [x] 解密xxx - **涩图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_setutime"` - [x] 来份[涩图/二次元/风景/车万] - [x] 添加[涩图/二次元/风景/车万][P站图片ID] diff --git a/control/cd.go b/control/cd.go new file mode 100644 index 00000000..830cbe99 --- /dev/null +++ b/control/cd.go @@ -0,0 +1,92 @@ +package control + +import ( + "encoding/binary" + "strings" + "time" + + b14 "github.com/fumiama/go-base16384" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" + + "github.com/FloatTech/ZeroBot-Plugin/utils/process" +) + +var startTime int64 + +func init() { + // 插件冲突检测 会在本群发送一条消息并在约 1s 后撤回 + zero.OnFullMatch("插件冲突检测", zero.OnlyGroup, zero.AdminPermission, zero.OnlyToMe).SetBlock(true).FirstPriority(). + Handle(func(ctx *zero.Ctx) { + tok, err := genToken() + if err != nil { + return + } + t := message.Text("●cd" + tok) + startTime = time.Now().Unix() + id := ctx.SendChain(t) + process.SleepAbout1sTo2s() + ctx.DeleteMessage(id) + }) + + zero.OnRegex("^●cd([\u4e00-\u9fa5]{4})$", zero.OnlyGroup).SetBlock(true).FirstPriority(). + Handle(func(ctx *zero.Ctx) { + tok := ctx.State["regex_matched"].([]string)[1] + if isValidToken(tok) && time.Now().Unix()-startTime < 10 { + msg := "" + gid := ctx.Event.GroupID + ForEach(func(key string, manager *Control) bool { + if manager.IsEnabledIn(gid) { + msg += "\xfe\xff" + key + } + return true + }) + if len(msg) > 2 { + my, err := b14.UTF16be2utf8(b14.EncodeString(msg[2:])) + mys := "●cd●" + helper.BytesToString(my) + if err == nil { + id := ctx.SendChain(message.Text(mys)) + process.SleepAbout1sTo2s() + ctx.DeleteMessage(id) + } + } + } + }) + + zero.OnRegex("^●cd●(.*)", zero.OnlyGroup).SetBlock(true).FirstPriority(). + Handle(func(ctx *zero.Ctx) { + msg, err := b14.UTF82utf16be(helper.StringToBytes(ctx.State["regex_matched"].([]string)[1])) + if err == nil { + gid := ctx.Event.GroupID + for _, s := range strings.Split(b14.DecodeString(msg), "\xfe\xff") { + mu.RLock() + c, ok := managers[s] + mu.RUnlock() + if ok && c.IsEnabledIn(gid) { + c.Disable(gid) + } + } + } + }) +} + +func genToken() (tok string, err error) { + timebytes := make([]byte, 8) + binary.BigEndian.PutUint64(timebytes, uint64(time.Now().Unix())) + timebytes, err = b14.UTF16be2utf8(b14.Encode(timebytes[1:])) + if err == nil { + tok = helper.BytesToString(timebytes) + } + return +} + +func isValidToken(tok string) (yes bool) { + s, err := b14.UTF82utf16be(helper.StringToBytes(tok)) + if err == nil { + timebytes := make([]byte, 1, 8) + timebytes = append(timebytes, b14.Decode(s)...) + yes = time.Now().Unix()-int64(binary.BigEndian.Uint64(timebytes)) < 10 + } + return +} diff --git a/control/cd_test.go b/control/cd_test.go new file mode 100644 index 00000000..6a238d47 --- /dev/null +++ b/control/cd_test.go @@ -0,0 +1,19 @@ +package control + +import "testing" + +func TestGenToken(t *testing.T) { + tok, err := genToken() + if err == nil { + t.Log(tok) + t.Log(isValidToken(tok)) + t.Fail() + } else { + t.Fatal(err) + } +} + +func TestMaru(t *testing.T) { + t.Log(len("\xff")) + t.Fail() +} diff --git a/go.mod b/go.mod index 348caea7..ebe97fed 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/FloatTech/bot-manager v1.0.0 github.com/fogleman/gg v1.3.0 github.com/fumiama/cron v1.3.0 + github.com/fumiama/go-base16384 v1.2.1 github.com/gin-gonic/gin v1.7.4 github.com/golang/protobuf v1.5.2 github.com/gorilla/websocket v1.4.2 diff --git a/go.sum b/go.sum index e28802bf..1bb9df70 100644 --- a/go.sum +++ b/go.sum @@ -29,6 +29,8 @@ github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzP github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo= github.com/fumiama/cron v1.3.0/go.mod h1:bz5Izvgi/xEUI8tlBN8BI2jr9Moo8N4or0KV8xXuPDY= +github.com/fumiama/go-base16384 v1.2.1 h1:6OGprW8g/95m2ocmryHi8mipZ7bx9StFMZDKEqLvMiA= +github.com/fumiama/go-base16384 v1.2.1/go.mod h1:1HTC0QFL7BjS0DuO5Qm+fBYKQkHqmAapLbRpCxrhPXQ= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.7.4 h1:QmUZXrvJ9qZ3GfWvQ+2wnW/1ePrTEJqPKMYEU3lD/DM= diff --git a/main.go b/main.go index f2eefb5a..1be9fd64 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_manager" // 群管 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh" // 拼音首字母缩写释义工具 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode" // 在线运行代码 - _ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 在线运行代码 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 翻译 // 娱乐类 _ "github.com/FloatTech/ZeroBot-Plugin-Gif" // 制图 diff --git a/plugin_atri/atri.go b/plugin_atri/atri.go index 3ee8666f..411d17d2 100644 --- a/plugin_atri/atri.go +++ b/plugin_atri/atri.go @@ -11,6 +11,8 @@ import ( zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" + + "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) var ( @@ -26,18 +28,18 @@ func init() { // 插件主体 zero.OnFullMatch("ATRI醒醒", zero.AdminPermission).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { enable = true - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randText("嗯呜呜……夏生先生……?")) }) zero.OnFullMatch("ATRI睡吧", zero.AdminPermission).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { enable = false - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randText("Zzz……Zzz……")) }) zero.OnFullMatch("萝卜子", atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() switch rand.Intn(2) { case 0: ctx.SendChain(randText("萝卜子是对机器人的蔑称!", "是亚托莉......萝卜子可是对机器人的蔑称")) @@ -47,18 +49,18 @@ func init() { // 插件主体 }) zero.OnFullMatchGroup([]string{"喜欢", "爱你", "爱", "suki", "daisuki", "すき", "好き", "贴贴", "老婆", "亲一个", "mua"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randImage("SUKI.jpg", "SUKI1.jpg", "SUKI2.png")) }) zero.OnKeywordGroup([]string{"草你妈", "操你妈", "脑瘫", "废柴", "fw", "five", "废物", "战斗", "爬", "爪巴", "sb", "SB", "傻B"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio - 1). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randImage("FN.jpg", "WQ.jpg", "WQ1.jpg")) }) zero.OnFullMatchGroup([]string{"早安", "早哇", "早上好", "ohayo", "哦哈哟", "お早う", "早好", "早"}, atriSwitch()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { now := time.Now().Hour() - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() switch { case now < 6: // 凌晨 ctx.SendChain(message.Reply(ctx.Event.MessageID), randText( @@ -99,7 +101,7 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { now := time.Now().Hour() if now > 11 && now < 15 { // 中午 - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(message.Reply(ctx.Event.MessageID), randText( "午安w", "午觉要好好睡哦,ATRI会陪伴在你身旁的w", @@ -111,7 +113,7 @@ func init() { // 插件主体 zero.OnFullMatchGroup([]string{"晚安", "oyasuminasai", "おやすみなさい", "晚好", "晚上好"}, atriSwitch()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { now := time.Now().Hour() - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() switch { case now < 6: // 凌晨 ctx.SendChain(message.Reply(ctx.Event.MessageID), randText( @@ -153,7 +155,7 @@ func init() { // 插件主体 }) zero.OnKeywordGroup([]string{"高性能", "太棒了", "すごい", "sugoi", "斯国一", "よかった"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randText( "当然,我是高性能的嘛~!", "小事一桩,我是高性能的嘛", @@ -174,7 +176,7 @@ func init() { // 插件主体 }) zero.OnKeywordGroup([]string{"没事", "没关系", "大丈夫", "还好", "不要紧", "没出大问题", "没伤到哪"}, atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randText( "当然,我是高性能的嘛~!", "没事没事,因为我是高性能的嘛!嗯哼!", @@ -189,26 +191,26 @@ func init() { // 插件主体 zero.OnKeywordGroup([]string{"好吗", "是吗", "行不行", "能不能", "可不可以"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() if rand.Intn(2) == 0 { ctx.SendChain(randImage("YES.png", "NO.jpg")) } }) zero.OnKeywordGroup([]string{"啊这"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() if rand.Intn(2) == 0 { ctx.SendChain(randImage("AZ.jpg", "AZ1.jpg")) } }) zero.OnKeywordGroup([]string{"我好了"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(message.Reply(ctx.Event.MessageID), randText("不许好!", "憋回去!")) }) zero.OnFullMatchGroup([]string{"?", "?", "¿"}, atriSwitch(), atriSleep()).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() switch rand.Intn(5) { case 0: ctx.SendChain(randText("?", "?", "嗯?", "(。´・ω・)ん?", "ん?")) @@ -227,7 +229,7 @@ func init() { // 插件主体 }) zero.OnKeyword("答应我", atriSwitch(), atriSleep(), zero.OnlyToMe).SetBlock(true).SetPriority(prio). Handle(func(ctx *zero.Ctx) { - time.Sleep(time.Second * 1) + process.SleepAbout1sTo2s() ctx.SendChain(randText("我无法回应你的请求")) }) } diff --git a/plugin_b14/main.go b/plugin_b14/main.go new file mode 100644 index 00000000..438e9e10 --- /dev/null +++ b/plugin_b14/main.go @@ -0,0 +1,38 @@ +package b14coder + +import ( + base14 "github.com/fumiama/go-base16384" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" + "github.com/wdvxdr1123/ZeroBot/utils/helper" + + "github.com/FloatTech/ZeroBot-Plugin/control" +) + +func init() { + en := control.Register("base16384", &control.Options{ + DisableOnDefault: false, + Help: "base16384加解密\n" + + "- 加密xxx\n- 解密xxx", + }) + en.OnRegex(`^加密(.*)`).SetBlock(true).ThirdPriority(). + 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(es)) + } else { + ctx.SendChain(message.Text("加密失败!")) + } + }) + en.OnRegex("^解密([\u4e00-\u9fa5]*)$").SetBlock(true).ThirdPriority(). + 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("解密失败!")) + } + }) +} diff --git a/plugin_diana/data/text.go b/plugin_diana/data/text.go index 16232f87..599a06b1 100644 --- a/plugin_diana/data/text.go +++ b/plugin_diana/data/text.go @@ -5,16 +5,15 @@ import ( "crypto/md5" "errors" "io" - "math/rand" "net/http" "os" "sync" - "time" log "github.com/sirupsen/logrus" "github.com/wdvxdr1123/ZeroBot/utils/helper" "github.com/FloatTech/ZeroBot-Plugin/utils/file" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) const ( @@ -35,7 +34,7 @@ var ( func init() { go func() { - time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000))) + process.SleepAbout1sTo2s() err := os.MkdirAll(datapath, 0755) if err != nil { panic(err) diff --git a/plugin_reborn/load.go b/plugin_reborn/load.go index 4c9495dc..ae8d9b12 100644 --- a/plugin_reborn/load.go +++ b/plugin_reborn/load.go @@ -3,15 +3,14 @@ package reborn import ( "encoding/json" "io" - "math/rand" "net/http" "os" - "time" wr "github.com/mroth/weightedrand" log "github.com/sirupsen/logrus" "github.com/FloatTech/ZeroBot-Plugin/utils/file" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) const ( @@ -31,7 +30,7 @@ var ( func init() { go func() { - time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000))) + process.SleepAbout1sTo2s() err := os.MkdirAll(datapath, 0755) if err != nil { panic(err) diff --git a/plugin_translation/tl.go b/plugin_translation/tl.go index b7d846bd..b931f95f 100644 --- a/plugin_translation/tl.go +++ b/plugin_translation/tl.go @@ -13,6 +13,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" "github.com/FloatTech/ZeroBot-Plugin/control" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) var ( @@ -57,7 +58,7 @@ func init() { } info := gjson.ParseBytes(rely) repo := info.Get("data.0") - time.Sleep(time.Second) + process.SleepAbout1sTo2s() ctx.SendChain(message.Text(repo.Get("value.0"))) }) } diff --git a/utils/process/sleep.go b/utils/process/sleep.go new file mode 100644 index 00000000..a67d8d89 --- /dev/null +++ b/utils/process/sleep.go @@ -0,0 +1,10 @@ +package process + +import ( + "math/rand" + "time" +) + +func SleepAbout1sTo2s() { + time.Sleep(time.Second + time.Millisecond*time.Duration(rand.Intn(1000))) +}