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

Function init

plugin/klala/k.go:28–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func init() { // 主函数
29 en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
30 DisableOnDefault: false,
31 Brief: "星穹铁道面板查询",
32 Help: "- *xx面板\n" +
33 "- *更新面板\n" +
34 "- *绑定xxx\n" +
35 "- *设置CD为xs",
36 })
37 en.OnRegex(preFix+`(.*)面板$`, initdata).SetBlock(true).Handle(func(ctx *zero.Ctx) {
38 wife := getWifeOrWq()
39 currentTime := time.Now().Unix()
40 uid := strconv.Itoa(getuid(strconv.FormatInt(ctx.Event.UserID, 10)))
41 if uid == "0" {
42 ctx.SendChain(message.At(ctx.Event.UserID), message.Text("-未绑定uid\n-第一次使用请发送\"*绑定xxx\""))
43 return
44 }
45 key := ctx.State["regex_matched"].([]string)[1]
46 if key == "" {
47 return
48 }
49 if key == "更新" {
50 if currentTime-lastExecutionTime < cds {
51 ctx.SendChain(message.Text("-全局时间冷却中,剩余时间", cds-currentTime+lastExecutionTime, "s"))
52 return
53 }
54 lastExecutionTime = currentTime
55 msg, err := saveRoel(uid)
56 if err != nil {
57 ctx.SendChain(message.At(ctx.Event.UserID), message.Text(err))
58 return
59 }
60 ctx.SendChain(message.At(ctx.Event.UserID), message.Text("\n", msg))
61 return
62 }
63 wifeid := wife.findnames("wife", key)
64 key = wife.idmap("wife", wifeid)
65 if key == "" {
66 ctx.SendChain(message.At(ctx.Event.UserID), message.Text("-请输入角色全名"))
67 return
68 }
69 data, err := os.ReadFile(jsPath + uid + ".klala")
70 if err != nil {
71 ctx.SendChain(message.At(ctx.Event.UserID), message.Text("-未找到本地缓存数据,请\"*更新面板\""))
72 return
73 }
74 var t thisdata
75 err = json.Unmarshal(data, &t)
76 if err != nil {
77 ctx.SendChain(message.Text("ERROR: ", err))
78 return
79 }
80 // 获取角色序列
81 var n = -1
82 // 匹配角色
83 for i, v := range t.RoleData {
84 if key == v.Name {
85 n = i

Callers

nothing calls this directly

Calls 6

drawcardMethod · 0.95
getWifeOrWqFunction · 0.85
getuidFunction · 0.85
saveRoelFunction · 0.85
findnamesMethod · 0.80
idmapMethod · 0.80

Tested by

no test coverage detected