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

Function init

plugin/klala/klala.go:23–112  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21)
22
23func init() { // 主函数
24 en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
25 DisableOnDefault: false,
26 Brief: "星穹铁道图鉴查询",
27 Help: "- *(强制)更新图鉴\n" +
28 "- *图鉴列表\n" +
29 "- *xx图鉴\n" +
30 "- *xx材料|素材",
31 PrivateDataFolder: "klala",
32 })
33 en.OnRegex(preFix + `(.*)(材料|素材|图鉴)$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
34 if file.IsNotExist(en.DataFolder() + "star-rail-atlas") {
35 ctx.SendChain(message.Text("请先发送\"更新图鉴\"!"))
36 return
37 }
38 word := ctx.State["regex_matched"].([]string)[1] // 关键字
39 if word == "" {
40 return
41 }
42 t, err := os.ReadFile(en.DataFolder() + "star-rail-atlas/path.json") // 获取文件
43 if err != nil {
44 ctx.SendChain(message.Text("获取路径文件失败", err))
45 return
46 }
47 var paths wikimap
48 _ = json.Unmarshal(t, &paths)
49 // 匹配类型
50 var path string
51 var ok bool
52 switch ctx.State["regex_matched"].([]string)[2] {
53 case "材料", "素材":
54 path, ok = paths.findhow(word)
55 case "图鉴":
56 path, ok = paths.findwhat(word)
57 }
58 if !ok {
59 ctx.SendChain(message.Text("未找到该", ctx.State["regex_matched"].([]string)[2]))
60 return
61 }
62 ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + en.DataFolder() + "star-rail-atlas" + path))
63 })
64 en.OnRegex(`^*(强制)?更新图鉴$`).SetBlock(true).Handle(func(ctx *zero.Ctx) {
65 var cmd *exec.Cmd
66 var p = file.BOTPATH + "/" + en.DataFolder()
67 if ctx.State["regex_matched"].([]string)[1] != "" {
68 if err := os.RemoveAll(p + "star-rail-atlas"); err != nil {
69 ctx.SendChain(message.Text("-删除失败", err))
70 return
71 }
72 }
73 if file.IsNotExist(en.DataFolder() + "star-rail-atlas") {
74 cmd = exec.Command("git", "clone", gitteURL)
75 cmd.Dir = p
76 } else {
77 cmd = exec.Command("git", "pull")
78 cmd.Dir = p + "star-rail-atlas/"
79 }
80 output, err := cmd.CombinedOutput()

Callers

nothing calls this directly

Calls 2

findhowMethod · 0.95
findwhatMethod · 0.95

Tested by

no test coverage detected