Skip to content

Commit 2a4aa39

Browse files
feat: configurable custom coin name (#950)
1 parent 26fcb5a commit 2a4aa39

File tree

6 files changed

+48
-18
lines changed

6 files changed

+48
-18
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,8 @@ print("run[CQ:image,file="+j["img"]+"]")
13091309

13101310
- [x] 查看钱包排名
13111311

1312+
- [x] 设置硬币名称[ATRI币]
1313+
13121314
</details>
13131315
<details>
13141316
<summary>据意查句</summary>

plugin/mcfish/fish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func init() {
6969
}
7070
money := wallet.GetWalletOf(uid)
7171
if money < 100 {
72-
ctx.SendChain(message.Text("你钱包当前只有", money, "ATRI币,无法完成支付"))
72+
ctx.SendChain(message.Text("你钱包当前只有", money, wallet.GetWalletName(), ",无法完成支付"))
7373
return
7474
}
7575
err = wallet.InsertWalletOf(uid, -100)

plugin/qqwife/favorSystem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func init() {
117117
}
118118
// 输出结果
119119
if mood == 0 {
120-
ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor))
120+
ctx.SendChain(message.Text("你花了", moneyToFavor, wallet.GetWalletName(), "买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor))
121121
} else {
122-
ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor))
122+
ctx.SendChain(message.Text("你花了", moneyToFavor, wallet.GetWalletName(), "买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor))
123123
}
124124
})
125125
engine.OnFullMatch("好感度列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).

plugin/robbery/robbery.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func init() {
3737
}
3838
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
3939
DisableOnDefault: false,
40-
Brief: "打劫别人的ATRI币",
40+
Brief: "打劫别人的钱包",
4141
Help: "- 打劫[对方Q号|@对方QQ]\n" +
4242
"1. 受害者钱包少于1000不能被打劫\n" +
4343
"2. 打劫成功率 40%\n" +
@@ -142,8 +142,8 @@ func init() {
142142
ctx.SendChain(message.At(uid), message.Text("[ERROR]:犯罪记录写入失败\n", err))
143143
}
144144

145-
ctx.SendChain(message.At(uid), message.Text("打劫成功,钱包增加:", userIncrMoney, "ATRI币"))
146-
ctx.SendChain(message.At(victimID), message.Text("保险公司对您进行了赔付,您实际损失:", victimDecrMoney, "ATRI币"))
145+
ctx.SendChain(message.At(uid), message.Text("打劫成功,钱包增加:", userIncrMoney, wallet.GetWalletName()))
146+
ctx.SendChain(message.At(victimID), message.Text("保险公司对您进行了赔付,您实际损失:", victimDecrMoney, wallet.GetWalletName()))
147147
})
148148
}
149149

plugin/score/draw.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212
"time"
1313

14+
"github.com/FloatTech/AnimeAPI/wallet"
1415
"github.com/FloatTech/floatbox/file"
1516
"github.com/FloatTech/gg"
1617
"github.com/FloatTech/imgfactory"
@@ -84,8 +85,8 @@ func drawScore16(a *scdata) (image.Image, error) {
8485
return nil, err
8586
}
8687
canvas.DrawStringAnchored(hourWord, 350, 280, 0, 0)
87-
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 350, 350, 0, 0)
88-
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 350, 400, 0, 0)
88+
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), 350, 350, 0, 0)
89+
canvas.DrawStringAnchored("当前"+wallet.GetWalletName()+":"+strconv.Itoa(a.score), 350, 400, 0, 0)
8990
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 350, 450, 0, 0)
9091
// draw Info(Time,etc.)
9192
getTime := time.Now().Format("2006-01-02 15:04:05")
@@ -161,8 +162,8 @@ func drawScore15(a *scdata) (image.Image, error) {
161162
if err = canvas.LoadFontFace(text.FontFile, float64(back.Bounds().Size().X)*0.04); err != nil {
162163
return nil, err
163164
}
164-
canvas.DrawString(a.nickname+fmt.Sprintf(" ATRI币+%d", a.inc), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.3)
165-
canvas.DrawString("当前ATRI币:"+strconv.FormatInt(int64(a.score), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.4)
165+
canvas.DrawString(a.nickname+fmt.Sprintf(" %s+%d", wallet.GetWalletName(), a.inc), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.3)
166+
canvas.DrawString("当前"+wallet.GetWalletName()+":"+strconv.FormatInt(int64(a.score), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.4)
166167
canvas.DrawString("LEVEL:"+strconv.FormatInt(int64(a.rank), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.5)
167168
canvas.DrawRectangle(float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.55, float64(back.Bounds().Size().X)*0.6, float64(back.Bounds().Size().Y)*0.1)
168169
canvas.SetRGB255(150, 150, 150)
@@ -247,8 +248,8 @@ func drawScore17(a *scdata) (image.Image, error) {
247248
if err = canvas.ParseFontFace(data, 20); err != nil {
248249
return nil, err
249250
}
250-
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 40, float64(imgDY-90), 0, 0)
251-
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 40, float64(imgDY-60), 0, 0)
251+
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), 40, float64(imgDY-90), 0, 0)
252+
canvas.DrawStringAnchored("当前"+wallet.GetWalletName()+":"+strconv.Itoa(a.score), 40, float64(imgDY-60), 0, 0)
252253
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 40, float64(imgDY-30), 0, 0)
253254

254255
// Draw Info(Time, etc.)
@@ -477,15 +478,15 @@ func customtext(a *scdata, fontdata []byte, cw, ch, aw float64, textcolor color.
477478
return
478479
}
479480

480-
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh, 0, 0.5)
481+
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh, 0, 0.5)
481482
canvas.DrawStringAnchored("EXP + 1", ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh+canvas.FontHeight(), 0, 1)
482483

483484
err = canvas.ParseFontFace(fontdata, (ch-sch)/2/4)
484485
if err != nil {
485486
return
486487
}
487488

488-
canvas.DrawStringAnchored("你有 "+strconv.Itoa(a.score)+" 枚ATRI币", ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4*3, 0, 0.5)
489+
canvas.DrawStringAnchored("你有 "+strconv.Itoa(a.score)+" 枚"+wallet.GetWalletName(), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4*3, 0, 0.5)
489490

490491
img = canvas.Image()
491492
return

plugin/wallet/wallet.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import (
55
"math"
66
"os"
77
"strconv"
8+
"strings"
89
"time"
910

1011
"github.com/FloatTech/AnimeAPI/wallet"
12+
"github.com/FloatTech/floatbox/binary"
1113
"github.com/FloatTech/floatbox/file"
1214
ctrl "github.com/FloatTech/zbpctrl"
1315
"github.com/FloatTech/zbputils/control"
@@ -23,21 +25,35 @@ func init() {
2325
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
2426
DisableOnDefault: false,
2527
Brief: "钱包",
26-
Help: "- 查看我的钱包\n- 查看钱包排名",
28+
Help: "- 查看我的钱包\n- 查看钱包排名\n- 设置硬币名称XXX",
2729
PrivateDataFolder: "wallet",
2830
})
2931
cachePath := en.DataFolder() + "cache/"
32+
coinNameFile := en.DataFolder() + "coin_name.txt"
3033
go func() {
3134
_ = os.RemoveAll(cachePath)
3235
err := os.MkdirAll(cachePath, 0755)
3336
if err != nil {
3437
panic(err)
3538
}
39+
// 更改硬币名称
40+
var coinName string
41+
if file.IsExist(coinNameFile) {
42+
content, err := os.ReadFile(coinNameFile)
43+
if err != nil {
44+
panic(err)
45+
}
46+
coinName = binary.BytesToString(content)
47+
} else {
48+
// 旧版本数据
49+
coinName = "ATRI币"
50+
}
51+
wallet.SetWalletName(coinName)
3652
}()
3753
en.OnFullMatch("查看我的钱包").SetBlock(true).Handle(func(ctx *zero.Ctx) {
3854
uid := ctx.Event.UserID
3955
money := wallet.GetWalletOf(uid)
40-
ctx.SendChain(message.At(uid), message.Text("你的钱包当前有", money, "ATRI币"))
56+
ctx.SendChain(message.At(uid), message.Text("你的钱包当前有", money, wallet.GetWalletName()))
4157
})
4258

4359
en.OnFullMatch("查看钱包排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
@@ -62,7 +78,7 @@ func init() {
6278
return
6379
}
6480
if len(st) == 0 {
65-
ctx.SendChain(message.Text("ERROR: 当前没人获取过ATRI币"))
81+
ctx.SendChain(message.Text("ERROR: 当前没人获取过", wallet.GetWalletName()))
6682
return
6783
} else if len(st) > 10 {
6884
st = st[:10]
@@ -98,7 +114,7 @@ func init() {
98114
}
99115
err = chart.BarChart{
100116
Font: font,
101-
Title: "ATRI币排名(1天只刷新1次)",
117+
Title: wallet.GetWalletName() + "排名(1天只刷新1次)",
102118
Background: chart.Style{
103119
Padding: chart.Box{
104120
Top: 40,
@@ -122,4 +138,15 @@ func init() {
122138
}
123139
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
124140
})
141+
en.OnPrefix("设置硬币名称", zero.OnlyToMe, zero.SuperUserPermission).SetBlock(true).
142+
Handle(func(ctx *zero.Ctx) {
143+
coinName := strings.TrimSpace(ctx.State["args"].(string))
144+
err := os.WriteFile(coinNameFile, binary.StringToBytes(coinName), 0644)
145+
if err != nil {
146+
ctx.SendChain(message.Text("ERROR: ", err))
147+
return
148+
}
149+
wallet.SetWalletName(coinName)
150+
ctx.SendChain(message.Text("记住啦~"))
151+
})
125152
}

0 commit comments

Comments
 (0)