From 87e32979040fc2c7c7299d22623d1a0054ffc4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8E=AB=E6=80=9D=E6=BD=8B?= <55676105+shudorcl@users.noreply.github.com> Date: Tue, 22 Mar 2022 12:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E5=88=B6=E9=80=80=E7=BE=A4=E6=8F=90?= =?UTF-8?q?=E9=86=92+=E8=B0=83=E6=95=B4=E7=85=8E=E8=9B=8B=E7=BD=91?= =?UTF-8?q?=E6=97=A0=E8=81=8A=E5=9B=BE=E8=A7=A6=E5=8F=91=20(#166)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim * 优化了更多插件中使用空格的体验 - 优化了music bilibili image_finder 中使用空格的体验 - 补上了plugin_bilibili中未实现的vup开头触发 - 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版 * 小调整 - 考虑到屌字既难打又有碍观瞻,改为正则匹配`[屌|弔|吊]图` - 增加了退群提醒的定制 * - 修复退群提醒本身忘记修改了的问题 --- README.md | 4 ++-- plugin/jandan/jandan.go | 6 ++--- plugin/manager/manager.go | 48 +++++++++++++++++++++++++++++++++++---- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e9f1532f..1d37c646 100644 --- a/README.md +++ b/README.md @@ -350,8 +350,8 @@ print("run[CQ:image,file="+j["img"]+"]") - **b站视频链接解析** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_parse"` - [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF - **煎蛋网无聊图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan"` - - [x] 来份屌图 - - [x] 更新屌图 + - [x] 来份[屌|弔|吊]图 + - [x] 更新[屌|弔|吊]图 - **月幕galgame图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal"` - [x] 随机galCG - [x] 随机gal表情包 diff --git a/plugin/jandan/jandan.go b/plugin/jandan/jandan.go index d3493d81..bc1623ed 100644 --- a/plugin/jandan/jandan.go +++ b/plugin/jandan/jandan.go @@ -25,7 +25,7 @@ const ( func init() { engine := control.Register("jandan", order.AcquirePrio(), &control.Options{ DisableOnDefault: false, - Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n", + Help: "煎蛋网无聊图\n- 来份[屌|弔|吊]图\n- 更新[屌|弔|吊]图\n", PublicDataFolder: "Jandan", }) @@ -44,7 +44,7 @@ func init() { logrus.Printf("[jandan]读取%d张图片", n) }() - engine.OnFullMatch("来份屌图").SetBlock(true). + engine.OnRegex(`来份[屌|弔|吊]图`).SetBlock(true). Handle(func(ctx *zero.Ctx) { u, err := getRandomPicture() if err != nil { @@ -54,7 +54,7 @@ func init() { ctx.SendChain(message.Image(u)) }) - engine.OnFullMatch("更新屌图", zero.SuperUserPermission).SetBlock(true). + engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { ctx.Send("少女更新中...") webpageURL := api diff --git a/plugin/manager/manager.go b/plugin/manager/manager.go index 8e34a00c..da31233e 100644 --- a/plugin/manager/manager.go +++ b/plugin/manager/manager.go @@ -48,8 +48,10 @@ const ( "- 取消在\"cron\"的提醒\n" + "- 列出所有提醒\n" + "- 翻牌\n" + - "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像\n" + + "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] [{id}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像 {id}是被欢迎者QQ号\n" + "- 测试欢迎语\n" + + "- 设置告别辞 参数同设置欢迎语\n" + + "- 测试告别辞\n" + "- [开启 | 关闭]入群验证" ) @@ -76,6 +78,10 @@ func init() { // 插件主体 if err != nil { panic(err) } + err = db.Create("farewell", &welcome{}) + if err != nil { + panic(err) + } }() // 升为管理 @@ -430,8 +436,14 @@ func init() { // 插件主体 engine.OnNotice().SetBlock(false). Handle(func(ctx *zero.Ctx) { if ctx.Event.NoticeType == "group_decrease" { - userid := ctx.Event.UserID - ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + var w welcome + err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) + if err == nil { + ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg))) + } else { + userid := ctx.Event.UserID + ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + } } }) // 设置欢迎语 @@ -459,6 +471,32 @@ func init() { // 插件主体 ctx.SendChain(message.Text("欢迎~")) } }) + // 设置告别辞 + engine.OnRegex(`^设置告别辞([\s\S]*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + w := &welcome{ + GrpID: ctx.Event.GroupID, + Msg: ctx.State["regex_matched"].([]string)[1], + } + err := db.Insert("farewell", w) + if err == nil { + ctx.SendChain(message.Text("记住啦!")) + } else { + ctx.SendChain(message.Text("出错啦: ", err)) + } + }) + // 测试告别辞 + engine.OnFullMatch("测试告别辞", zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + var w welcome + err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) + if err == nil { + ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg))) + } else { + userid := ctx.Event.UserID + ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + } + }) // 入群后验证开关 engine.OnRegex(`^(.*)入群验证$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { @@ -543,11 +581,13 @@ func init() { // 插件主体 // 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg) func welcometocq(ctx *zero.Ctx, welcome string) string { - nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("nickname").Str at := "[CQ:at,qq=" + strconv.FormatInt(ctx.Event.UserID, 10) + "]" avatar := "[CQ:image,file=" + "http://q4.qlogo.cn/g?b=qq&nk=" + strconv.FormatInt(ctx.Event.UserID, 10) + "&s=640]" + id := strconv.FormatInt(ctx.Event.UserID, 10) + nickname := ctx.CardOrNickName(ctx.Event.UserID) cqstring := strings.ReplaceAll(welcome, "{at}", at) cqstring = strings.ReplaceAll(cqstring, "{nickname}", nickname) cqstring = strings.ReplaceAll(cqstring, "{avatar}", avatar) + cqstring = strings.ReplaceAll(cqstring, "{id}", id) return cqstring }