MCPcopy
hub / github.com/FloatTech/ZeroBot-Plugin / init

Function init

plugin/wallet/wallet.go:25–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

23)
24
25func init() {
26 en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
27 DisableOnDefault: false,
28 Brief: "钱包",
29 Help: "- 查看钱包排名\n" +
30 "- 设置硬币名称XX\n" +
31 "- 管理钱包余额[+金额|-金额][@xxx]\n" +
32 "- 查看我的钱包|查看钱包余额[@xxx]\n" +
33 "- 钱包转账[金额][@xxx]\n" +
34 "注:仅超级用户能“管理钱包余额”\n",
35 PrivateDataFolder: "wallet",
36 })
37 cachePath := en.DataFolder() + "cache/"
38 coinNameFile := en.DataFolder() + "coin_name.txt"
39 go func() {
40 _ = os.RemoveAll(cachePath)
41 err := os.MkdirAll(cachePath, 0755)
42 if err != nil {
43 panic(err)
44 }
45 // 更改硬币名称
46 var coinName string
47 if file.IsExist(coinNameFile) {
48 content, err := os.ReadFile(coinNameFile)
49 if err != nil {
50 panic(err)
51 }
52 coinName = binary.BytesToString(content)
53 } else {
54 // 旧版本数据
55 coinName = "ATRI币"
56 }
57 wallet.SetWalletName(coinName)
58 }()
59
60 en.OnFullMatch("查看钱包排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
61 Handle(func(ctx *zero.Ctx) {
62 gid := strconv.FormatInt(ctx.Event.GroupID, 10)
63 today := time.Now().Format("20060102")
64 drawedFile := cachePath + gid + today + "walletRank.png"
65 if file.IsExist(drawedFile) {
66 ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
67 return
68 }
69 // 无缓存获取群员列表
70 temp := ctx.GetThisGroupMemberListNoCache().Array()
71 usergroup := make([]int64, len(temp))
72 for i, info := range temp {
73 usergroup[i] = info.Get("user_id").Int()
74 }
75 // 获取钱包信息
76 st, err := wallet.GetGroupWalletOf(true, usergroup...)
77 if err != nil {
78 ctx.SendChain(message.Text("ERROR: ", err))
79 return
80 }
81 if len(st) == 0 {
82 ctx.SendChain(message.Text("ERROR: 当前没人获取过", wallet.GetWalletName()))

Callers

nothing calls this directly

Calls 2

FormatMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected