MCPcopy Create free account
hub / github.com/FloatTech/ZeroBot-Plugin-Playground / init

Function init

plugin/exXiaoGuoFan/example.go:23–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21)
22
23func init() {
24 engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
25 DisableOnDefault: false,
26 Brief: "小锅饭的示例",
27 Help: "- hello\n- 完全匹配\n- 完全匹配组1 | 完全匹配组2\n- 关键词你好\n- /命令\n- 前缀你好\n- 你好后缀\n" +
28 "- 小锅饭正在洗澡\n- /用户 -n 小锅饭 -a 3\n- 牛逼\n- 消息检测\n- 文本\n- 艾特\n- 图片\n" +
29 "- 回复\n- 语音\n- 表情\n- 音乐\n- tts\n- 戳一戳\n",
30 })
31 // hello
32 engine.OnFullMatch("hello").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
33 ctx.SendChain(message.Text("hello world!"))
34 })
35
36 // matcher
37 engine.OnFullMatch("完全匹配").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
38 matched := ctx.State["matched"].(string)
39 ctx.SendChain(message.Text("完全匹配的匹配词: ", matched))
40 })
41 engine.OnFullMatchGroup([]string{"完全匹配组1", "完全匹配组2"}).SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
42 matched := ctx.State["matched"].(string)
43 ctx.SendChain(message.Text("完全匹配组的匹配词: ", matched))
44 })
45 engine.OnKeyword("关键词").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
46 keyword := ctx.State["keyword"].(string)
47 ctx.SendChain(message.Text("关键词匹配的关键词: ", keyword))
48 })
49 engine.OnCommand("命令").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
50 command := ctx.State["command"].(string)
51 args := ctx.State["args"].(string)
52 ctx.SendChain(message.Text("命令匹配的命令: ", command, "\n命令匹配的参数: ", args))
53 })
54 engine.OnPrefix("前缀").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
55 prefix := ctx.State["prefix"].(string)
56 args := ctx.State["args"].(string)
57 ctx.SendChain(message.Text("前缀匹配的前缀: ", prefix, "\n前缀匹配的参数: ", args))
58 })
59 engine.OnRegex(`(.*)正在(.*)`).SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
60 regexMatched := ctx.State["regex_matched"].([]string)
61 ctx.SendChain(message.Text("正则匹配的匹配组: ", regexMatched))
62 })
63 engine.OnSuffix("后缀").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
64 suffix := ctx.State["suffix"].(string)
65 args := ctx.State["args"].(string)
66 ctx.SendChain(message.Text("后缀匹配的后缀: ", suffix, "\n后缀匹配的参数: ", args))
67 })
68 engine.OnShell("用户", user{}).SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
69 args := ctx.State["args"].([]string)
70 u := ctx.State["flag"].(*user)
71 ctx.SendChain(message.Text("shell匹配的结构体: ", u, "\nshell匹配的参数: ", args))
72 })
73
74 // message
75 engine.OnFullMatch("文本").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
76 ctx.SendChain(message.Text("文本"))
77 })
78 engine.OnFullMatch("艾特").SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
79 ctx.SendChain(message.At(ctx.Event.UserID), message.Text("艾特你"))
80 })

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected