From 2a78a602e2e30bf93e89800d7a7cac066bc262d5 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: Sun, 27 Mar 2022 12:56:57 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20shindan=20add=20=E9=BB=84=E6=B2=B9?= =?UTF-8?q?=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + plugin/shindan/shindan.go | 57 ++++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1d37c646ef..24a724f9aa 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 异世界转生[@xxx] - [x] 卖萌[@xxx] - [x] 抽老婆[@xxx] + - [x] 黄油角色[@xxx] - **AIWife** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/aiwife"` - [x] waifu | 随机waifu(从[100000个AI生成的waifu](https://www.thiswaifudoesnotexist.net/)中随机一位) - **gif** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/gif"` diff --git a/plugin/shindan/shindan.go b/plugin/shindan/shindan.go index 2cc8165bb9..292c82c57c 100644 --- a/plugin/shindan/shindan.go +++ b/plugin/shindan/shindan.go @@ -24,33 +24,52 @@ func init() { "- 卖萌[@xxx]\n" + "- 抽老婆[@xxx]", }) - engine.OnPrefix("异世界转生", number(587874)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handle) - engine.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handle) - engine.OnPrefix("卖萌", number(360578)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handle) - engine.OnPrefix("抽老婆", number(1075116)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handle) + engine.OnPrefix("异世界转生", number(587874)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic) + engine.OnPrefix("今天是什么少女", number(162207)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic) + engine.OnPrefix("卖萌", number(360578)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handletxt) + engine.OnPrefix("抽老婆", number(1075116)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlecq) + engine.OnPrefix("黄油角色", number(1115465)).SetBlock(true).Limit(ctxext.LimitByUser).Handle(handlepic) } -// shindanmaker 处理函数 -func handle(ctx *zero.Ctx) { +func handletxt(ctx *zero.Ctx) { // 获取名字 name := ctx.NickName() // 调用接口 txt, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name) if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) + ctx.SendChain(message.Text("ERROR:", err)) + return } - // TODO: 可注入 - switch ctx.State["id"].(int64) { - case 587874, 162207: - data, err := text.RenderToBase64(txt, text.FontFile, 400, 20) - if err != nil { - log.Errorln("[shindan]:", err) - } - if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 { - ctx.SendChain(message.Text("ERROR: 可能被风控了")) - } - default: - ctx.Send(txt) + ctx.SendChain(message.Text(txt)) +} + +func handlecq(ctx *zero.Ctx) { + // 获取名字 + name := ctx.NickName() + // 调用接口 + txt, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.Send(txt) +} + +func handlepic(ctx *zero.Ctx) { + // 获取名字 + name := ctx.NickName() + // 调用接口 + txt, err := shindanmaker.Shindanmaker(ctx.State["id"].(int64), name) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + data, err := text.RenderToBase64(txt, text.FontFile, 400, 20) + if err != nil { + log.Errorln("[shindan]:", err) + } + if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) } }