From c46ca1d4c25dc6061fa73677615f8b0fbe7435d0 Mon Sep 17 00:00:00 2001 From: Kanri Date: Fri, 15 Oct 2021 21:43:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=8E=A8=20ctx.Send=20->=20ctx.SendChai?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/rule.go | 16 ++++++++-------- main.go | 3 ++- plugin_acgimage/classify.go | 25 ++++++++++++------------- plugin_ai_false/ai_false.go | 4 ++-- plugin_diana/bing.go | 10 +++++----- plugin_diana/zhiwang.go | 4 ++-- plugin_manager/manager.go | 31 ++++++++++++++++--------------- plugin_minecraft/manager.go | 11 +++++++++-- plugin_music/selecter.go | 2 +- plugin_runcode/code_runner.go | 2 +- plugin_saucenao/searcher.go | 6 +++--- plugin_setutime/setu_geter.go | 8 ++++---- plugin_shindan/shindan.go | 8 ++++++++ 13 files changed, 73 insertions(+), 57 deletions(-) diff --git a/control/rule.go b/control/rule.go index f12bb59d..ad5b0a96 100644 --- a/control/rule.go +++ b/control/rule.go @@ -140,10 +140,10 @@ func init() { _ = ctx.Parse(&model) service, ok := Lookup(model.Args) if !ok { - ctx.Send("没有找到指定服务!") + ctx.SendChain(message.Text("没有找到指定服务!")) } service.Enable(ctx.Event.GroupID) - ctx.Send(message.Text("已启用服务: " + model.Args)) + ctx.SendChain(message.Text("已启用服务: " + model.Args)) }) zero.OnCommandGroup([]string{"禁用", "disable"}, zero.AdminPermission, zero.OnlyGroup). @@ -152,10 +152,10 @@ func init() { _ = ctx.Parse(&model) service, ok := Lookup(model.Args) if !ok { - ctx.Send("没有找到指定服务!") + ctx.SendChain(message.Text("没有找到指定服务!")) } service.Disable(ctx.Event.GroupID) - ctx.Send(message.Text("已关闭服务: " + model.Args)) + ctx.SendChain(message.Text("已关闭服务: " + model.Args)) }) zero.OnCommandGroup([]string{"用法", "usage"}, zero.AdminPermission, zero.OnlyGroup). @@ -164,12 +164,12 @@ func init() { _ = ctx.Parse(&model) service, ok := Lookup(model.Args) if !ok { - ctx.Send("没有找到指定服务!") + ctx.SendChain(message.Text("没有找到指定服务!")) } if service.options.Help != "" { - ctx.Send(service.options.Help) + ctx.SendChain(message.Text(service.options.Help)) } else { - ctx.Send("该服务无帮助!") + ctx.SendChain(message.Text("该服务无帮助!")) } }) @@ -187,7 +187,7 @@ func init() { } return true }) - ctx.Send(message.Text(msg)) + ctx.SendChain(message.Text(msg)) }) } } diff --git a/main.go b/main.go index 8bde8f59..f5d520d5 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,7 @@ import ( "github.com/sirupsen/logrus" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/driver" + "github.com/wdvxdr1123/ZeroBot/message" ) var ( @@ -121,7 +122,7 @@ func main() { // 帮助 zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).FirstPriority(). Handle(func(ctx *zero.Ctx) { - ctx.Send(banner) + ctx.SendChain(message.Text(banner)) }) select {} } diff --git a/plugin_acgimage/classify.go b/plugin_acgimage/classify.go index 5fe82194..5c5ea40d 100644 --- a/plugin_acgimage/classify.go +++ b/plugin_acgimage/classify.go @@ -46,10 +46,10 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { url := ctx.State["regex_matched"].([]string)[1] if !strings.HasPrefix(url, "http") { - ctx.Send("URL非法!") + ctx.SendChain(message.Text("URL非法!")) } else { randapi = url - ctx.Send("设置好啦") + ctx.SendChain(message.Text("设置好啦")) } }) // 有保护的随机图片 @@ -61,14 +61,14 @@ func init() { // 插件主体 replyClass(ctx, dhash, class, false, lastvisit, comment) }() } else { - ctx.Send("你太快啦!") + ctx.SendChain(message.Text("你太快啦!")) } }) // 直接随机图片,无r18保护,后果自负。如果出r18图可尽快通过发送"太涩了"撤回 engine.OnFullMatch("直接随机", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { if block { - ctx.Send("请稍后再试哦") + ctx.SendChain(message.Text("请稍后再试哦")) } else if randapi != "" { block = true var url string @@ -77,7 +77,7 @@ func init() { // 插件主体 } else { url = randapi } - setLastMsg(ctx.Event.GroupID, ctx.Send(message.Image(url).Add("cache", "0"))) + setLastMsg(ctx.Event.GroupID, ctx.SendChain(message.Image(url).Add("cache", "0"))) block = false } }) @@ -89,7 +89,7 @@ func init() { // 插件主体 // 上传一张图进行评价 engine.OnKeywordGroup([]string{"评价图片"}, zero.OnlyGroup, picture.CmdMatch, picture.MustGiven).SetBlock(true).SetPriority(24). Handle(func(ctx *zero.Ctx) { - ctx.Send("少女祈祷中...") + ctx.SendChain(message.Text("少女祈祷中...")) for _, url := range ctx.State["image_url"].([]string) { go func(target string) { class, lastvisit, dhash, comment := classify.Classify(target, true) @@ -101,7 +101,7 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { dhash := ctx.State["regex_matched"].([]string)[1] if len(dhash) == 5*3 { - ctx.Send(message.Image(apihead + dhash)) + ctx.SendChain(message.Image(apihead + dhash)) } }) } @@ -124,19 +124,18 @@ func replyClass(ctx *zero.Ctx, dhash string, class int, noimg bool, lv int64, co if dhash != "" && !noimg { b14, err3 := url.QueryUnescape(dhash) if err3 == nil { - ctx.Send(comment + "\n给你点提示哦:" + b14) + ctx.SendChain(message.Text(comment + "\n给你点提示哦:" + b14)) ctx.Event.GroupID = 0 - ctx.Send(img) + ctx.SendChain(message.Text(img)) } } else { - ctx.Send(comment) + ctx.SendChain(message.Text(comment)) } } else { - comment := message.Text(comment) if !noimg { - ctx.SendChain(img, comment) + ctx.SendChain(img, message.Text(comment)) } else { - ctx.SendChain(message.Reply(ctx.Event.MessageID), comment) + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(comment)) } } } diff --git a/plugin_ai_false/ai_false.go b/plugin_ai_false/ai_false.go index efbc9df2..37b23d2d 100644 --- a/plugin_ai_false/ai_false.go +++ b/plugin_ai_false/ai_false.go @@ -35,9 +35,9 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { err := os.RemoveAll("data/cache/*") if err != nil { - ctx.Send("错误: " + err.Error()) + ctx.SendChain(message.Text("错误: ", err.Error())) } else { - ctx.Send("成功!") + ctx.SendChain(message.Text("成功!")) } }) } diff --git a/plugin_diana/bing.go b/plugin_diana/bing.go index 46b7abd2..3e97ff95 100644 --- a/plugin_diana/bing.go +++ b/plugin_diana/bing.go @@ -2,11 +2,11 @@ package diana import ( - fmt "fmt" "math/rand" "time" zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" "github.com/FloatTech/ZeroBot-Plugin/control" "github.com/FloatTech/ZeroBot-Plugin/plugin_diana/data" @@ -28,22 +28,22 @@ func init() { Handle(func(ctx *zero.Ctx) { rand.Seed(time.Now().UnixNano()) // 绕过第一行发病 - ctx.Send((*data.Array)[rand.Intn(len(*data.Array)-1)+1]) + ctx.SendChain(message.Text((*data.Array)[rand.Intn(len(*data.Array)-1)+1])) }) // 逆天 engine.OnFullMatch("发大病").SetBlock(true). Handle(func(ctx *zero.Ctx) { // 第一行是发病 - ctx.Send((*data.Array)[0]) + ctx.SendChain(message.Text((*data.Array)[0])) }) // 增加小作文 engine.OnRegex(`^教你一篇小作文(.*)$`, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { err := data.AddText(ctx.State["regex_matched"].([]string)[1]) if err != nil { - ctx.Send(fmt.Sprintf("ERROR: %v", err)) + ctx.SendChain(message.Text("ERROR: ", err)) } else { - ctx.Send("记住啦!") + ctx.SendChain(message.Text("记住啦!")) } }) } diff --git a/plugin_diana/zhiwang.go b/plugin_diana/zhiwang.go index 2654b22c..3b4dbd0d 100644 --- a/plugin_diana/zhiwang.go +++ b/plugin_diana/zhiwang.go @@ -37,12 +37,12 @@ func init() { zhiwangjson := zhiwangapi(msg) if zhiwangjson == nil || zhiwangjson.Code != 0 { - ctx.Send("api返回错误") + ctx.SendChain(message.Text("api返回错误")) return } if len(zhiwangjson.Data.Related) == 0 { - ctx.Send("枝网没搜到,查重率为0%,我的评价是:一眼真") + ctx.SendChain(message.Text("枝网没搜到,查重率为0%,我的评价是:一眼真")) return } diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 495417fb..0eb5d92f 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -58,7 +58,7 @@ func init() { // 插件主体 // 菜单 zero.OnFullMatch("群管系统", zero.AdminPermission).SetBlock(true).FirstPriority(). Handle(func(ctx *zero.Ctx) { - ctx.Send(hint) + ctx.SendChain(message.Text(hint)) }) // 升为管理 zero.OnRegex(`^升为管理.*?(\d+)`, zero.OnlyGroup, zero.SuperUserPermission).SetBlock(true).SetPriority(40). @@ -254,9 +254,9 @@ func init() { // 插件主体 ts.Grpid = uint64(ctx.Event.GroupID) if ts.Enable { go timer.RegisterTimer(ts, true) - ctx.Send("记住了~") + ctx.SendChain(message.Text("记住了~")) } else { - ctx.Send("参数非法!") + ctx.SendChain(message.Text("参数非法!")) } } }) @@ -273,9 +273,9 @@ func init() { // 插件主体 t.Enable = false delete(*timer.Timers, ti) // 避免重复取消 _ = timer.SaveTimers() - ctx.Send("取消成功~") + ctx.SendChain(message.Text("取消成功~")) } else { - ctx.Send("没有这个定时器哦~") + ctx.SendChain(message.Text("没有这个定时器哦~")) } } }) @@ -283,7 +283,7 @@ func init() { // 插件主体 zero.OnFullMatch("列出所有提醒", zero.AdminPermission).SetBlock(true).SetPriority(40). Handle(func(ctx *zero.Ctx) { if ctx.Event.GroupID > 0 { - ctx.Send(fmt.Sprint(timer.ListTimers(uint64(ctx.Event.GroupID)))) + ctx.SendChain(message.Text(timer.ListTimers(uint64(ctx.Event.GroupID)))) } }) // 随机点名 @@ -330,9 +330,9 @@ func init() { // 插件主体 if ctx.Event.NoticeType == "group_increase" { word, ok := config.Welcome[uint64(ctx.Event.GroupID)] if ok { - ctx.Send(word) + ctx.SendChain(message.Text(word)) } else { - ctx.Send("欢迎~") + ctx.SendChain(message.Text("欢迎~")) } enable, ok1 := config.Checkin[uint64(ctx.Event.GroupID)] if ok1 && enable { @@ -349,7 +349,7 @@ func init() { // 插件主体 ans, err := strconv.Atoi(text) if err == nil { if ans != r { - ctx.Send("答案不对哦,再想想吧~") + ctx.SendChain(message.Text("答案不对哦,再想想吧~")) return false } return true @@ -362,12 +362,12 @@ func init() { // 插件主体 recv, cancel := next.Repeat() select { case <-time.After(time.Minute): - ctx.Send("拜拜啦~") + ctx.SendChain(message.Text("拜拜啦~")) ctx.SetGroupKick(ctx.Event.GroupID, uid, false) cancel() case <-recv: cancel() - ctx.Send("答对啦~") + ctx.SendChain(message.Text("答对啦~")) } } } @@ -384,9 +384,9 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { config.Welcome[uint64(ctx.Event.GroupID)] = ctx.State["regex_matched"].([]string)[1] if saveConfig() == nil { - ctx.Send("记住啦!") + ctx.SendChain(message.Text("记住啦!")) } else { - ctx.Send("出错啦!") + ctx.SendChain(message.Text("出错啦!")) } }) // 入群验证开关 @@ -402,9 +402,9 @@ func init() { // 插件主体 return } if saveConfig() == nil { - ctx.Send("已" + option) + ctx.SendChain(message.Text("已", option)) } else { - ctx.Send("出错啦!") + ctx.SendChain(message.Text("出错啦!")) } }) // 运行 CQ 码 @@ -413,6 +413,7 @@ func init() { // 插件主体 var cmd = ctx.State["regex_matched"].([]string)[1] cmd = strings.ReplaceAll(cmd, "[", "[") cmd = strings.ReplaceAll(cmd, "]", "]") + // 可注入,权限为主人 ctx.Send(cmd) }) } diff --git a/plugin_minecraft/manager.go b/plugin_minecraft/manager.go index dcff1662..265aef4a 100644 --- a/plugin_minecraft/manager.go +++ b/plugin_minecraft/manager.go @@ -1,3 +1,10 @@ +/* + * @Author: Kanri + * @Date: 2021-10-15 21:23:14 + * @LastEditors: Kanri + * @LastEditTime: 2021-10-15 21:40:37 + * @Description: + */ // Package minecraft MCSManager package minecraft @@ -35,7 +42,7 @@ func init() { _ = ctx.Parse(&model) ctx.SendChain(message.Text("开启服务器: ", model.Args, ".....")) result := start(model.Args) - ctx.Send(result) + ctx.SendChain(message.Text(result)) }) engine.OnCommand("mcstop").SetBlock(true). Handle(func(ctx *zero.Ctx) { @@ -43,7 +50,7 @@ func init() { _ = ctx.Parse(&model) ctx.SendChain(message.Text("开启服务器: ", model.Args, ".....")) result := stop(model.Args) - ctx.Send(result) + ctx.SendChain(message.Text(result)) }) } diff --git a/plugin_music/selecter.go b/plugin_music/selecter.go index 0f29be4e..c2f3d361 100644 --- a/plugin_music/selecter.go +++ b/plugin_music/selecter.go @@ -32,7 +32,7 @@ func init() { }).OnRegex("^(.{0,2})点歌(.{1,25})$").SetBlock(true).FirstPriority(). Handle(func(ctx *zero.Ctx) { if !limit.Load(ctx.Event.UserID).Acquire() { - ctx.Send("请稍后重试0x0...") + ctx.SendChain(message.Text("请稍后重试0x0...")) return } // switch 平台 diff --git a/plugin_runcode/code_runner.go b/plugin_runcode/code_runner.go index c63aadf9..f1d47c4f 100644 --- a/plugin_runcode/code_runner.go +++ b/plugin_runcode/code_runner.go @@ -107,7 +107,7 @@ func init() { }).OnRegex(`^>runcode\s(.+?)\s([\s\S]+)$`).SetBlock(true).SecondPriority(). Handle(func(ctx *zero.Ctx) { if !limit.Load(ctx.Event.UserID).Acquire() { - ctx.Send("请稍后重试0x0...") + ctx.SendChain(message.Text("请稍后重试0x0...")) } else { language := ctx.State["regex_matched"].([]string)[1] language = strings.ToLower(language) diff --git a/plugin_saucenao/searcher.go b/plugin_saucenao/searcher.go index c76ce0b7..42178153 100644 --- a/plugin_saucenao/searcher.go +++ b/plugin_saucenao/searcher.go @@ -27,7 +27,7 @@ func init() { // 插件主体 engine.OnRegex(`^搜图(\d+)$`).SetBlock(true).FirstPriority(). Handle(func(ctx *zero.Ctx) { id, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64) - ctx.Send("少女祈祷中......") + ctx.SendChain(message.Text("少女祈祷中......")) // 获取P站插图信息 illust, err := pixiv.Works(id) if err != nil { @@ -51,14 +51,14 @@ func init() { // 插件主体 ), ) } else { - ctx.Send("图片不存在!") + ctx.SendChain(message.Text("图片不存在!")) } }) // 以图搜图 engine.OnKeywordGroup([]string{"以图搜图", "搜索图片", "以图识图"}, picture.CmdMatch, picture.MustGiven).SetBlock(true).FirstPriority(). Handle(func(ctx *zero.Ctx) { // 开始搜索图片 - ctx.Send("少女祈祷中......") + ctx.SendChain(message.Text("少女祈祷中......")) for _, pic := range ctx.State["image_url"].([]string) { fmt.Println(pic) if result, err := saucenao.SauceNAO(pic); err != nil { diff --git a/plugin_setutime/setu_geter.go b/plugin_setutime/setu_geter.go index eb9682f6..d92c4067 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -169,7 +169,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("ERROR: ", err)) return } - ctx.Send("添加成功") + ctx.SendChain(message.Text("添加成功")) }) engine.OnRegex(`^删除(.*?)(\d+)$`, firstValueInList(pool.List), zero.SuperUserPermission).SetBlock(true).SetPriority(22). @@ -180,10 +180,10 @@ func init() { // 插件主体 ) // 查询数据库 if err := pool.DB.Del(imgtype, fmt.Sprintf("WHERE pid=%d", id)); err != nil { - ctx.Send(fmt.Sprintf("ERROR: %v", err)) + ctx.SendChain(message.Text("ERROR: ", err)) return } - ctx.Send("删除成功") + ctx.SendChain(message.Text("删除成功")) }) // 查询数据库涩图数量 @@ -200,7 +200,7 @@ func init() { // 插件主体 state = append(state, ": ") state = append(state, fmt.Sprintf("%d", num)) } - ctx.Send(strings.Join(state, "")) + ctx.SendChain(message.Text(state)) }) } diff --git a/plugin_shindan/shindan.go b/plugin_shindan/shindan.go index b5e03965..bbff45f3 100644 --- a/plugin_shindan/shindan.go +++ b/plugin_shindan/shindan.go @@ -1,3 +1,10 @@ +/* + * @Author: Kanri + * @Date: 2021-10-15 21:23:14 + * @LastEditors: Kanri + * @LastEditTime: 2021-10-15 21:42:51 + * @Description: + */ // Package shindan 基于 https://shindanmaker.com 的测定小功能 package shindan @@ -52,6 +59,7 @@ func handle(ctx *zero.Ctx) { if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) } + // TODO: 可注入 ctx.Send(text) } From d375a3bbbb5647e0c4f09b2d5a1e810f80ef86c1 Mon Sep 17 00:00:00 2001 From: Kanri Date: Fri, 15 Oct 2021 22:02:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20=E5=B0=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/rule.go | 1 + plugin_diana/zhiwang.go | 1 + plugin_minecraft/manager.go | 7 ------- utils/dl/dl.go | 1 + utils/math/math.go | 4 ++-- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/control/rule.go b/control/rule.go index ad5b0a96..ac040247 100644 --- a/control/rule.go +++ b/control/rule.go @@ -69,6 +69,7 @@ func (m *Control) Disable(groupID int64) { m.Unlock() } +// IsEnabledIn 开启群 func (m *Control) IsEnabledIn(gid int64) bool { m.RLock() var c grpcfg diff --git a/plugin_diana/zhiwang.go b/plugin_diana/zhiwang.go index 3b4dbd0d..7b477074 100644 --- a/plugin_diana/zhiwang.go +++ b/plugin_diana/zhiwang.go @@ -1,3 +1,4 @@ +// Package diana 嘉然相关 package diana import ( diff --git a/plugin_minecraft/manager.go b/plugin_minecraft/manager.go index 265aef4a..5195b5cf 100644 --- a/plugin_minecraft/manager.go +++ b/plugin_minecraft/manager.go @@ -1,10 +1,3 @@ -/* - * @Author: Kanri - * @Date: 2021-10-15 21:23:14 - * @LastEditors: Kanri - * @LastEditTime: 2021-10-15 21:40:37 - * @Description: - */ // Package minecraft MCSManager package minecraft diff --git a/utils/dl/dl.go b/utils/dl/dl.go index dcc3bea6..414e5ef1 100644 --- a/utils/dl/dl.go +++ b/utils/dl/dl.go @@ -7,6 +7,7 @@ import ( "os" ) +// DownloadTo 下载到路径 func DownloadTo(url, file string) error { resp, err := http.Get(url) if err == nil { diff --git a/utils/math/math.go b/utils/math/math.go index e364456e..ecb78445 100644 --- a/utils/math/math.go +++ b/utils/math/math.go @@ -1,7 +1,7 @@ // Package math 计算实用工具 package math -// min 返回两数最大值,该函数将被内联 +// Max 返回两数最大值,该函数将被内联 func Max(a, b int) int { if a > b { return a @@ -9,7 +9,7 @@ func Max(a, b int) int { return b } -// min 返回两数最小值,该函数将被内联 +// Min 返回两数最小值,该函数将被内联 func Min(a, b int) int { if a > b { return b