forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shindan.go
82 lines (75 loc) · 2.44 KB
/
shindan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Package shindan 基于 https://shindanmaker.com 的测定小功能
package shindan
import (
"github.com/FloatTech/AnimeAPI/shindanmaker"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
"github.com/wdvxdr1123/ZeroBot/utils/helper"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/img/text"
)
func init() {
engine := control.Register("shindan", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "shindan测定",
Help: "- 今天是什么少女[@xxx]\n" +
"- 异世界转生[@xxx]\n" +
"- 卖萌[@xxx]\n" +
"- 今日老婆[@xxx]\n" +
"- 黄油角色[@xxx]",
})
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)
}
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))
return
}
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 {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
if id := ctx.SendChain(message.Image("base64://" + helper.BytesToString(data))); id.ID() == 0 {
ctx.SendChain(message.Text("ERROR: 可能被风控了"))
}
}
// 传入 shindanmaker id
func number(id int64) func(ctx *zero.Ctx) bool {
return func(ctx *zero.Ctx) bool {
ctx.State["id"] = id
return true
}
}