From 5d9ac50106b595d889313e22fb1695dba21876c0 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: Fri, 9 Dec 2022 23:23:56 +0800 Subject: [PATCH] fix: aireply: ent->enr & update README & optimize bilibili match (#519) --- README.md | 7 ++++++- plugin/ai_reply/main.go | 7 ++++--- plugin/bilibili/bilibilipush.go | 14 +++++++------- plugin/manager/manager.go | 6 +++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a877dda8..18c2bd8f 100644 --- a/README.md +++ b/README.md @@ -1424,7 +1424,12 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] @Bot 任意文本(任意一句话回复) - - [x] 设置回复模式[青云客 | 小爱] + - [x] 设置回复模式[青云客 | 小爱 | ChatGPT] + + - [x] 设置 ChatGPT SessionToken xxx + + - 注册和获取token可以参见这两篇文章:[注册](https://www.cnblogs.com/ranxi169/p/16954797.html) [获取token](https://juejin.cn/post/7174088036035067917) + ## 三种使用方法,推荐第一种 diff --git a/plugin/ai_reply/main.go b/plugin/ai_reply/main.go index 82610b5c..b74ebb56 100644 --- a/plugin/ai_reply/main.go +++ b/plugin/ai_reply/main.go @@ -156,7 +156,7 @@ func init() { // 插件主体 } ctx.SendChain(message.Text("设置成功")) }) - chatgptfile := ent.DataFolder() + "chatgpt.txt" + chatgptfile := enr.DataFolder() + "chatgpt.txt" cfg := &chatgpt.Config{ UA: chatgpt.UA, RefreshInterval: time.Hour, @@ -178,7 +178,7 @@ func init() { // 插件主体 } } }() - ent.OnRegex(`^设置\s*ChatGPT\s*SessionToken\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) { + enr.OnRegex(`^设置\s*ChatGPT\s*SessionToken\s*(.*)$`, zero.OnlyPrivate, zero.SuperUserPermission).SetBlock(true).Handle(func(ctx *zero.Ctx) { token := ctx.State["regex_matched"].([]string)[1] f, err := os.Create(chatgptfile) if err != nil { @@ -199,7 +199,8 @@ func init() { // 插件主体 }) ctx.SendChain(message.Text("设置成功")) }) - ent.OnFullMatch("重置ChatGPT连接").SetBlock(true).Handle(func(ctx *zero.Ctx) { + enr.OnFullMatch("重置ChatGPT连接").SetBlock(true).Handle(func(ctx *zero.Ctx) { chats.Reset(ctx.Event.UserID) + ctx.SendChain(message.Text("成功")) }) } diff --git a/plugin/bilibili/bilibilipush.go b/plugin/bilibili/bilibilipush.go index 61fd1701..e2f6ee3e 100644 --- a/plugin/bilibili/bilibilipush.go +++ b/plugin/bilibili/bilibilipush.go @@ -56,7 +56,7 @@ func init() { dbfile := dbpath + "push.db" bdb = initializePush(dbfile) - en.OnRegex(`^添加b站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`^添加[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64) name, err := getName(buid) if err != nil { @@ -73,7 +73,7 @@ func init() { } ctx.SendChain(message.Text("已添加" + name + "的订阅")) }) - en.OnRegex(`^取消b站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`^取消[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64) name, err := getName(buid) if err != nil { @@ -90,7 +90,7 @@ func init() { } ctx.SendChain(message.Text("已取消" + name + "的订阅")) }) - en.OnRegex(`^取消b站动态订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`^取消[B|b]站动态订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64) name, err := getName(buid) if err != nil { @@ -107,7 +107,7 @@ func init() { } ctx.SendChain(message.Text("已取消" + name + "的动态订阅")) }) - en.OnRegex(`^取消b站直播订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`^取消[B|b]站直播订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) { buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64) gid := ctx.Event.GroupID if gid == 0 { @@ -124,13 +124,13 @@ func init() { } ctx.SendChain(message.Text("已取消" + name + "的直播订阅")) }) - en.OnFullMatch("b站推送列表", zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`^[B|b]站推送列表$`, zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID if gid == 0 { gid = -ctx.Event.UserID } bpl := bdb.getAllPushByGroup(gid) - msg := "--------b站推送列表--------" + msg := "--------B站推送列表--------" for _, v := range bpl { if _, ok := upMap[v.BilibiliUID]; !ok { bdb.updateAllUp() @@ -158,7 +158,7 @@ func init() { ctx.SendChain(message.Text("ERROR: 可能被风控了")) } }) - en.OnFullMatch("拉取b站推送").SetBlock(true).Handle(func(ctx *zero.Ctx) { + en.OnRegex(`拉取[B|b]站推送$`).SetBlock(true).Handle(func(ctx *zero.Ctx) { err := sendDynamic(ctx) if err != nil { ctx.SendPrivateMessage(ctx.Event.UserID, message.Text("Error: bilibilipush,", err)) diff --git a/plugin/manager/manager.go b/plugin/manager/manager.go index 2b37f356..6580ad08 100644 --- a/plugin/manager/manager.go +++ b/plugin/manager/manager.go @@ -222,7 +222,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("那我就不手下留情了~")) }) // 修改名片 - engine.OnRegex(`^修改名片.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + engine.OnRegex(`^修改名片.*(\d+).*\s+(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { if len(ctx.State["regex_matched"].([]string)[2]) > 60 { ctx.SendChain(message.Text("名字太长啦!")) @@ -236,7 +236,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("嗯!已经修改了")) }) // 修改头衔 - engine.OnRegex(`^修改头衔.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + engine.OnRegex(`^修改头衔.*(\d+).*\s+(.*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { if len(ctx.State["regex_matched"].([]string)[1]) > 18 { ctx.SendChain(message.Text("头衔太长啦!")) @@ -250,7 +250,7 @@ func init() { // 插件主体 ctx.SendChain(message.Text("嗯!已经修改了")) }) // 申请头衔 - engine.OnRegex(`^申请头衔(.*)`, zero.OnlyGroup).SetBlock(true). + engine.OnRegex(`^申请头衔\s+(.*)$`, zero.OnlyGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { if len(ctx.State["regex_matched"].([]string)[1]) > 18 { ctx.SendChain(message.Text("头衔太长啦!"))