From aa08eb012085cb3c78708857f5c0e7e06e6eaa41 Mon Sep 17 00:00:00 2001 From: MoeMagicMango Date: Sat, 12 Feb 2022 20:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=87=E7=9A=84=E5=9B=9E?= =?UTF-8?q?=E5=A4=8D=20=E5=88=A0=E6=8E=89=E4=BA=86=E4=B8=80=E4=BA=9Bex?= =?UTF-8?q?=E7=9A=84=E8=AF=8D=E6=B1=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_thesaurus/chat.go | 38 ++++++++++++++++++++++++++++++++++++++ plugin_thesaurus/data.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 plugin_thesaurus/chat.go create mode 100644 plugin_thesaurus/data.go diff --git a/plugin_thesaurus/chat.go b/plugin_thesaurus/chat.go new file mode 100644 index 00000000..8aa68634 --- /dev/null +++ b/plugin_thesaurus/chat.go @@ -0,0 +1,38 @@ +// Package thesaurus 修改过的单纯回复插件 +package thesaurus + +import ( + "math/rand" + + control "github.com/FloatTech/zbputils/control" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" + + "github.com/FloatTech/ZeroBot-Plugin/order" +) + +const ( + dbpath = "data/Purechat/" + dbfile = dbpath + "kimoi_clear.json" +) + +var ( + engine = control.Register("thesaurus", order.AcquirePrio(), &control.Options{ + DisableOnDefault: ture, + Help: "thesaurus\n- 稍微干净一点的chat回复 删掉了一些有点ex的w((", + }) + kimogomap = make(kimogo, 256) + chatList = make([]string, 0, 256) +) + +func init() { + initPureChatList(func() { + engine.OnFullMatchGroup(chatList, zero.OnlyToMe).SetBlock(true).Handle( + func(ctx *zero.Ctx) { + key := ctx.MessageString() + val := *kimogomap[key] + text := val[rand.Intn(len(val))] + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) // 来自于 https://github.com/Kyomotoi/AnimeThesaurus 的回复 经过二次修改 + }) + }) +} \ No newline at end of file diff --git a/plugin_thesaurus/data.go b/plugin_thesaurus/data.go new file mode 100644 index 00000000..c64985c7 --- /dev/null +++ b/plugin_thesaurus/data.go @@ -0,0 +1,36 @@ +package thesaurus + +import ( + "encoding/json" + "os" + + "github.com/sirupsen/logrus" + + "github.com/FloatTech/zbputils/file" + "github.com/FloatTech/zbputils/process" + + "github.com/FloatTech/ZeroBot-Plugin/order" +) + +type kimogo = map[string]*[]string + +func initPureChatList(postinit func()) { + go func() { + defer order.DoneOnExit()() + process.SleepAbout1sTo2s() + _ = os.MkdirAll(dbpath, 0755) + data, err := file.GetLazyData(dbfile, true, true) + if err != nil { + panic(err) + } + err = json.Unmarshal(data, &kimogomap) + if err != nil { + panic(err) + } + for k := range kimogomap { + chatList = append(chatList, k) + } + logrus.Infoln("[purechat]加载", len(chatList), "条kimoi") + postinit() + }() +}