From 3b1ad2250fa80a86721a7a7d5e7fdcc14e7f87f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Fri, 2 Dec 2022 20:24:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=8D=E5=BA=93=E5=A2=9E=E5=8A=A0=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=A6=82=E7=8E=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + plugin/thesaurus/chat.go | 41 ++++++++++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ba146fdc..9405c0ec 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ zerobot [-h] [-n nickname] [-t token] [-u url] [-p prefix] [-d|w] [-c|s config.j `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/thesaurus"` - [x] 切换[kimo|傲娇|可爱]词库 + - [x] 设置词库触发概率0.x (0
diff --git a/plugin/thesaurus/chat.go b/plugin/thesaurus/chat.go index 3ba82c1d..f5886e61 100644 --- a/plugin/thesaurus/chat.go +++ b/plugin/thesaurus/chat.go @@ -21,7 +21,7 @@ func init() { engine := control.Register("thesaurus", &ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, Brief: "词典匹配回复", - Help: "- 切换[kimo|傲娇|可爱]词库", + Help: "- 切换[kimo|傲娇|可爱]词库\n- 设置词库触发概率0.x (0= 9 { + ctx.SendChain(message.Text("ERROR: 概率越界")) + return + } + n-- // 0~7 + gid := ctx.Event.GroupID + if gid == 0 { + gid = -ctx.Event.UserID + } + d := c.GetData(gid) + err := c.SetData(gid, (d&3)|(int64(n)<<59)) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -142,6 +167,9 @@ const ( func canmatch(typ int64) zero.Rule { return func(ctx *zero.Ctx) bool { + if zero.HasPicture(ctx) { + return false + } c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx]) if !ok { return false @@ -150,7 +178,8 @@ func canmatch(typ int64) zero.Rule { if gid == 0 { gid = -ctx.Event.UserID } - return c.GetData(gid) == typ + d := c.GetData(gid) + return d&3 == typ && rand.Int63n(10) <= d>>59 } }