MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / init

Function init

plugin/hs/run.go:43–95  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41)
42
43func init() {
44 engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
45 DisableOnDefault: false,
46 Brief: "炉石搜卡",
47 Help: "- 搜卡[xxxx]\n" +
48 "- [卡组代码xxx]\n" +
49 "- 更多搜卡指令参数:https://hs.fbigame.com/misc/searchhelp",
50 PrivateDataFolder: "hs",
51 }).ApplySingle(ctxext.DefaultSingle)
52 cachedir := file.BOTPATH + "/" + engine.DataFolder()
53 engine.OnRegex(`^搜卡(.+)$`).
54 SetBlock(true).Handle(func(ctx *zero.Ctx) {
55 List := ctx.State["regex_matched"].([]string)[1]
56 g := sh(List)
57 t := int(gjson.Get(g, `list.#`).Int())
58 if t == 0 {
59 ctx.SendChain(message.Text("查询为空!"))
60 return
61 }
62 var sk message.Message
63 for i := 0; i < t && i < 5; i++ {
64 cid := gjson.Get(g, `list.`+strconv.Itoa(i)+`.CardID`).String()
65 cachefile := cachedir + cid
66 if file.IsNotExist(cachefile) {
67 data, err := web.RequestDataWith(web.NewDefaultClient(),
68 `https://res.fbigame.com/hs/v13/`+cid+`.png?auth_key=`+
69 gjson.Get(g, `list.`+strconv.Itoa(i)+`.auth_key`).String(),
70 reqconf[0], reqconf[1], reqconf[2], nil)
71 if err == nil {
72 err = os.WriteFile(cachefile, data, 0644)
73 }
74 if err != nil {
75 continue
76 }
77 }
78 sk = append(sk, ctxext.FakeSenderForwardNode(ctx, message.Image("file:///"+cachefile)))
79 }
80 if id := ctx.SendGroupForwardMessage(
81 ctx.Event.GroupID,
82 sk,
83 ).Get("message_id").Int(); id == 0 {
84 ctx.SendChain(message.Text("ERROR: 可能被风控了"))
85 }
86 })
87 // 卡组
88 engine.OnRegex(`^[\s\S]*?(AAE[a-zA-Z0-9/\+=]{70,})[\s\S]*$`).
89 SetBlock(true).Handle(func(ctx *zero.Ctx) {
90 List := ctx.State["regex_matched"].([]string)[1]
91 ctx.SendChain(
92 message.Image(kz(List)),
93 )
94 })
95}
96
97func sh(s string) string {
98 data, err := web.RequestDataWith(web.NewDefaultClient(), "https://hs.fbigame.com", reqconf[0], reqconf[1], reqconf[2], nil)

Callers

nothing calls this directly

Calls 3

shFunction · 0.85
kzFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected