Skip to content

Commit

Permalink
feat: use wallet plugin to configure coin name
Browse files Browse the repository at this point in the history
  • Loading branch information
EatHatsuneShallots committed Aug 8, 2024
1 parent c9b241b commit 4cce0da
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,8 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 查看钱包排名

- [x] 设置硬币名称[ATRI币]

</details>
<details>
<summary>据意查句</summary>
Expand Down
27 changes: 26 additions & 1 deletion plugin/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,30 @@ func init() {
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "钱包",
Help: "- 查看我的钱包\n- 查看钱包排名",
Help: "- 查看我的钱包\n- 查看钱包排名\n- 设置硬币名称XXX",
PrivateDataFolder: "wallet",
})
cachePath := en.DataFolder() + "cache/"
coinNameFile := en.DataFolder() + "coin_name.txt"
go func() {
_ = os.RemoveAll(cachePath)
err := os.MkdirAll(cachePath, 0755)
if err != nil {
panic(err)
}
// 更改硬币名称
var coinName string
if file.IsExist(coinNameFile) {
content, err := os.ReadFile(coinNameFile)
if err != nil {
panic(err)
}
coinName = string(content)
} else {
// 旧版本数据
coinName = "ATRI币"
}
wallet.SetWalletName(coinName)
}()
en.OnFullMatch("查看我的钱包").SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand Down Expand Up @@ -122,4 +136,15 @@ func init() {
}
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
})
en.OnRegex(`^设置硬币名称\s*(.*)$`, zero.OnlyToMe, zero.SuperUserPermission).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
coinName := ctx.State["regex_matched"].([]string)[1]
err := os.WriteFile(coinNameFile, []byte(coinName), 0644)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
wallet.SetWalletName(coinName)
ctx.SendChain(message.Text("记住啦~"))
})
}

0 comments on commit 4cce0da

Please sign in to comment.