Skip to content

Commit

Permalink
fix(wallet): 修复钱包余额判断逻辑 (#957)
Browse files Browse the repository at this point in the history
- ”管理钱包余额“里的amount变量带符号
- “钱包转账”里的amount变量不带符号
  • Loading branch information
vatebur authored Aug 19, 2024
1 parent 5d2898b commit 31b7017
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 管理钱包余额[+金额|-金额][@xxx]

- [x] 查看我的钱包|查询钱包余额[@xxx]
- [x] 查看我的钱包|查看钱包余额[@xxx]

- [x] 钱包转账[金额][@xxx]

Expand Down
12 changes: 6 additions & 6 deletions plugin/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func init() {
Help: "- 查看钱包排名\n" +
"- 设置硬币名称XX\n" +
"- 管理钱包余额[+金额|-金额][@xxx]\n" +
"- 查看我的钱包|查询钱包余额[@xxx]\n" +
"- 查看我的钱包|查看钱包余额[@xxx]\n" +
"- 钱包转账[金额][@xxx]\n" +
"注:仅超级用户能“管理钱包余额”\n",
PrivateDataFolder: "wallet",
Expand Down Expand Up @@ -177,8 +177,8 @@ func init() {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("QQ号处理失败"))
return
}
if amount < wallet.GetWalletOf(uidInt) {
ctx.SendChain(message.Text("管理失败:对方钱包余额不足,扣款失败:"))
if amount+wallet.GetWalletOf(uidInt) < 0 {
ctx.SendChain(message.Text("管理失败:对方钱包余额不足,扣款失败"))
return
}
err = wallet.InsertWalletOf(uidInt, amount)
Expand All @@ -190,7 +190,7 @@ func init() {
})

// 保留用户习惯,兼容旧语法“查看我的钱包”
en.OnPrefixGroup([]string{`查询钱包余额`, `查看我的钱包`}).SetBlock(true).Limit(ctxext.LimitByGroup).
en.OnPrefixGroup([]string{`查看钱包余额`, `查看我的钱包`}).SetBlock(true).Limit(ctxext.LimitByGroup).
Handle(func(ctx *zero.Ctx) {
param := ctx.State["args"].(string)
var uidStr string
Expand All @@ -212,8 +212,8 @@ func init() {
Handle(func(ctx *zero.Ctx) {
param := strings.TrimSpace(ctx.State["args"].(string))

// 捕获修改的金额
re := regexp.MustCompile(`^[+-]?\d+$`)
// 捕获修改的金额,amount扣款金额恒正(要注意符号)
re := regexp.MustCompile(`^[+]?\d+$`)
amount, err := strconv.Atoi(re.FindString(param))
if err != nil || amount <= 0 {
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("输入额异常,请检查金额或at是否正常"))
Expand Down

0 comments on commit 31b7017

Please sign in to comment.