From 16e05e03201be9ebe810bed9704f2029f7799481 Mon Sep 17 00:00:00 2001 From: himawari <54976075+guohuiyuan@users.noreply.github.com> Date: Tue, 11 Jan 2022 10:07:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E9=AA=82=E4=BA=BA=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=20(#102)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix:vtb数据不用从zbp更新 * feat:独立骂人插件 * fix:修lint * feat:添加关键词 Co-authored-by: Guohuiyuan --- README.md | 4 +++ main.go | 1 + plugin_curse/curse.go | 50 ++++++++++++++++++++++++++++++++++++ plugin_curse/data.go | 36 ++++++++++++++++++++++++++ plugin_curse/model.go | 12 +++++++++ plugin_shadiao/shadiao.go | 18 ++++++------- plugin_shadiao/zuan.go | 29 --------------------- plugin_vtb_quotation/data.go | 2 +- 8 files changed, 112 insertions(+), 40 deletions(-) create mode 100644 plugin_curse/curse.go create mode 100644 plugin_curse/data.go create mode 100644 plugin_curse/model.go delete mode 100644 plugin_shadiao/zuan.go diff --git a/README.md b/README.md index c42c3eed..7fb0b08e 100644 --- a/README.md +++ b/README.md @@ -249,6 +249,10 @@ zerobot [-h] [-t token] [-u url] [-n nickname] [-p prefix] [-d|w] [-g 监听地 - **签到得分** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_score"` - [x] 签到 - [x] 获得签到背景[@xxx]|获得签到背景 +- **骂人** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse"` + - [x] 骂我 + - [x] 大力骂我 + - [x] @bot 他妈|公交车|你妈|操|屎|去死|快死|日|逼|尼玛|艾滋|癌症|有病|戴套|啊对对对|烦你|你爹|屮|tui|cnm - **TODO...** ## 使用方法 diff --git a/main.go b/main.go index f9839e0e..447373c0 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,7 @@ import ( _ "github.com/FloatTech/ZeroBot-Plugin/plugin_chouxianghua" // 说抽象话 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_coser" // 三次元小姐姐 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_cpstory" // cp短打 + _ "github.com/FloatTech/ZeroBot-Plugin/plugin_curse" // 骂人 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_fortune" // 运势 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_funny" // 笑话 _ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石 diff --git a/plugin_curse/curse.go b/plugin_curse/curse.go new file mode 100644 index 00000000..3836b456 --- /dev/null +++ b/plugin_curse/curse.go @@ -0,0 +1,50 @@ +// Package curse 骂人插件(求骂,自卫) +package curse + +import ( + "github.com/FloatTech/ZeroBot-Plugin/control" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/extension/rate" + "github.com/wdvxdr1123/ZeroBot/message" + "time" +) + +const ( + prio = 10 + minLevel = "min" + maxLevel = "max" +) + +var ( + engine = control.Register("curse", &control.Options{ + DisableOnDefault: false, + Help: "骂人(求骂,自卫)\n- 骂我\n- 大力骂我\n- @bot 他妈|公交车|你妈|操|屎|去死|快死|日|逼|尼玛|艾滋|癌症|有病|戴套|啊对对对|烦你|你爹|屮|tui|cnm", + }) + limit = rate.NewManager(time.Minute, 30) +) + +func init() { + engine.OnFullMatch("骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) { + if !limit.Load(ctx.Event.GroupID).Acquire() { + return + } + process.SleepAbout1sTo2s() + text := getRandomCurseByLevel(minLevel).Text + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) + }) + + engine.OnFullMatch("大力骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) { + if !limit.Load(ctx.Event.GroupID).Acquire() { + return + } + process.SleepAbout1sTo2s() + text := getRandomCurseByLevel(maxLevel).Text + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) + }) + engine.OnKeywordGroup([]string{"他妈", "公交车", "你妈", "操", "屎", "去死", "快死", "日", "逼", "尼玛", "艾滋", "癌症", "有病", "戴套", "啊对对对", "烦你", "你爹", "屮", "tui", "cnm"}, zero.OnlyToMe).SetBlock(true).SetPriority(prio). + Handle(func(ctx *zero.Ctx) { + text := getRandomCurseByLevel(maxLevel).Text + ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(text)) + }) +} diff --git a/plugin_curse/data.go b/plugin_curse/data.go new file mode 100644 index 00000000..0628cbe1 --- /dev/null +++ b/plugin_curse/data.go @@ -0,0 +1,36 @@ +package curse + +import ( + "github.com/FloatTech/ZeroBot-Plugin/utils/file" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" + "github.com/FloatTech/ZeroBot-Plugin/utils/sql" + "github.com/sirupsen/logrus" + "os" +) + +const ( + dbpath = "data/Curse/" + dbfile = dbpath + "curse.db" +) + +var ( + db = &sql.Sqlite{DBPath: dbfile} +) + +// 加载数据库 +func init() { + go func() { + process.SleepAbout1sTo2s() + _ = os.MkdirAll(dbpath, 0755) + _, err := file.GetLazyData(dbfile, false, true) + if err != nil { + panic(err) + } + err = db.Create("curse", &curse{}) + if err != nil { + panic(err) + } + c, _ := db.Count("curse") + logrus.Infoln("[curse]加载", c, "条骂人语录") + }() +} diff --git a/plugin_curse/model.go b/plugin_curse/model.go new file mode 100644 index 00000000..20fb7bd2 --- /dev/null +++ b/plugin_curse/model.go @@ -0,0 +1,12 @@ +package curse + +type curse struct { + ID uint32 `db:"id"` + Text string `db:"text"` + Level string `db:"level"` +} + +func getRandomCurseByLevel(level string) (c curse) { + _ = db.Find("curse", &c, "where level = '"+level+"' ORDER BY RANDOM() limit 1") + return +} diff --git a/plugin_shadiao/shadiao.go b/plugin_shadiao/shadiao.go index 8a7f0e98..ee704130 100644 --- a/plugin_shadiao/shadiao.go +++ b/plugin_shadiao/shadiao.go @@ -10,28 +10,26 @@ import ( ) const ( - chpURL = "https://chp.shadiao.app/api.php" - duURL = "https://du.shadiao.app/api.php" - pyqURL = "https://pyq.shadiao.app/api.php" - yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi" - chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0" - ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1" - // zuanURL = "https://zuanbot.com/api.php?level=min&lang=zh_cn" + chpURL = "https://chp.shadiao.app/api.php" + duURL = "https://du.shadiao.app/api.php" + pyqURL = "https://pyq.shadiao.app/api.php" + yduanziURL = "http://www.yduanzi.com/duanzi/getduanzi" + chayiURL = "https://api.lovelive.tools/api/SweetNothings/Web/0" + ganhaiURL = "https://api.lovelive.tools/api/SweetNothings/Web/1" ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36" chpReferer = "https://chp.shadiao.app/" duReferer = "https://du.shadiao.app/" pyqReferer = "https://pyq.shadiao.app/" yduanziReferer = "http://www.yduanzi.com/?utm_source=shadiao.app" loveliveReferer = "https://lovelive.tools/" - // zuanReferer = "https://zuanbot.com/" - prio = 10 + prio = 10 ) var ( engine = control.Register("shadiao", &control.Options{ DisableOnDefault: false, Help: "沙雕app\n" + - "- 骂他[@xxx]|骂他[qq号](停用)\n- 骂我(停用)\n- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子", + "- 哄我\n- 渣我\n- 来碗绿茶\n- 发个朋友圈\n- 来碗毒鸡汤\n- 讲个段子", }) limit = rate.NewManager(time.Minute, 60) ) diff --git a/plugin_shadiao/zuan.go b/plugin_shadiao/zuan.go deleted file mode 100644 index a706f461..00000000 --- a/plugin_shadiao/zuan.go +++ /dev/null @@ -1,29 +0,0 @@ -package shadiao - -/* -func init() { - engine.OnFullMatch("骂我").SetBlock(true).SetPriority(prio).Handle(func(ctx *zero.Ctx) { - if !limit.Load(ctx.Event.GroupID).Acquire() { - return - } - data, err := web.ReqWith(zuanURL, "GET", zuanReferer, ua) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(helper.BytesToString(data))) - }) - engine.OnRegex(`^骂他.*?(\d+)`, zero.OnlyGroup).SetBlock(true).SetPriority(40). - Handle(func(ctx *zero.Ctx) { - if !limit.Load(ctx.Event.GroupID).Acquire() { - return - } - data, err := web.ReqWith(zuanURL, "GET", "", ua) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.At(math.Str2Int64(ctx.State["regex_matched"].([]string)[1])), message.Text(helper.BytesToString(data))) - }) -} -*/ diff --git a/plugin_vtb_quotation/data.go b/plugin_vtb_quotation/data.go index 158b0078..c509083b 100644 --- a/plugin_vtb_quotation/data.go +++ b/plugin_vtb_quotation/data.go @@ -12,6 +12,6 @@ func init() { go func() { process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) - _, _ = file.GetLazyData(dbfile, false, true) + _, _ = file.GetLazyData(dbfile, false, false) }() }