-
Notifications
You must be signed in to change notification settings - Fork 2k
/
ymgal.go
88 lines (84 loc) · 2.66 KB
/
ymgal.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
83
84
85
86
87
88
// Package ymgal 月幕galgame
package ymgal
import (
"strings"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
engine := control.Register("ymgal", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "月幕galgame\n- 随机galCG\n- 随机gal表情包\n- galCG[xxx]\n- gal表情包[xxx]\n- 更新gal\n",
PublicDataFolder: "Ymgal",
})
getdb := ctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
dbfile := engine.DataFolder() + "ymgal.db"
_, err := engine.GetLazyData("ymgal.db", false)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
gdb, err = initialize(dbfile)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return false
}
return true
})
engine.OnRegex("^随机gal(CG|表情包)$", getdb).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
pictureType := ctx.State["regex_matched"].([]string)[1]
var y ymgal
if pictureType == "表情包" {
y = gdb.randomYmgal(emoticonType)
} else {
y = gdb.randomYmgal(cgType)
}
sendYmgal(y, ctx)
})
engine.OnRegex("^gal(CG|表情包)([一-龥ぁ-んァ-ヶA-Za-z0-9]{1,25})$", getdb).Limit(ctxext.LimitByUser).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
pictureType := ctx.State["regex_matched"].([]string)[1]
key := ctx.State["regex_matched"].([]string)[2]
var y ymgal
if pictureType == "CG" {
y = gdb.getYmgalByKey(cgType, key)
} else {
y = gdb.getYmgalByKey(emoticonType, key)
}
sendYmgal(y, ctx)
})
engine.OnFullMatch("更新gal", zero.SuperUserPermission, getdb).SetBlock(true).Handle(
func(ctx *zero.Ctx) {
ctx.Send("少女祈祷中......")
err := updatePic()
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.Send("ymgal数据库已更新")
})
}
func sendYmgal(y ymgal, ctx *zero.Ctx) {
if y.PictureList == "" {
ctx.SendChain(message.Text(zero.BotConfig.NickName[0] + "暂时没有这样的图呢"))
return
}
m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Text(y.Title))}
if y.PictureDescription != "" {
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Text(y.PictureDescription)))
}
for _, v := range strings.Split(y.PictureList, ",") {
m = append(m, ctxext.FakeSenderForwardNode(ctx, message.Image(v)))
}
if id := ctx.SendGroupForwardMessage(
ctx.Event.GroupID,
m).Get("message_id").Int(); id == 0 {
ctx.SendChain(message.Text("ERROR:可能被风控了"))
}
}