mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-18 20:50:12 +08:00
feat: configurable custom coin name (#950)
This commit is contained in:
parent
26fcb5aad5
commit
2a4aa39bab
@ -1309,6 +1309,8 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] 查看钱包排名
|
||||
|
||||
- [x] 设置硬币名称[ATRI币]
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>据意查句</summary>
|
||||
|
||||
@ -69,7 +69,7 @@ func init() {
|
||||
}
|
||||
money := wallet.GetWalletOf(uid)
|
||||
if money < 100 {
|
||||
ctx.SendChain(message.Text("你钱包当前只有", money, "ATRI币,无法完成支付"))
|
||||
ctx.SendChain(message.Text("你钱包当前只有", money, wallet.GetWalletName(), ",无法完成支付"))
|
||||
return
|
||||
}
|
||||
err = wallet.InsertWalletOf(uid, -100)
|
||||
|
||||
@ -117,9 +117,9 @@ func init() {
|
||||
}
|
||||
// 输出结果
|
||||
if mood == 0 {
|
||||
ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor))
|
||||
ctx.SendChain(message.Text("你花了", moneyToFavor, wallet.GetWalletName(), "买了一件女装送给了ta,ta很不喜欢,你们的好感度降低至", lastfavor))
|
||||
} else {
|
||||
ctx.SendChain(message.Text("你花了", moneyToFavor, "ATRI币买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor))
|
||||
ctx.SendChain(message.Text("你花了", moneyToFavor, wallet.GetWalletName(), "买了一件女装送给了ta,ta很喜欢,你们的好感度升至", lastfavor))
|
||||
}
|
||||
})
|
||||
engine.OnFullMatch("好感度列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||
|
||||
@ -37,7 +37,7 @@ func init() {
|
||||
}
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "打劫别人的ATRI币",
|
||||
Brief: "打劫别人的钱包",
|
||||
Help: "- 打劫[对方Q号|@对方QQ]\n" +
|
||||
"1. 受害者钱包少于1000不能被打劫\n" +
|
||||
"2. 打劫成功率 40%\n" +
|
||||
@ -142,8 +142,8 @@ func init() {
|
||||
ctx.SendChain(message.At(uid), message.Text("[ERROR]:犯罪记录写入失败\n", err))
|
||||
}
|
||||
|
||||
ctx.SendChain(message.At(uid), message.Text("打劫成功,钱包增加:", userIncrMoney, "ATRI币"))
|
||||
ctx.SendChain(message.At(victimID), message.Text("保险公司对您进行了赔付,您实际损失:", victimDecrMoney, "ATRI币"))
|
||||
ctx.SendChain(message.At(uid), message.Text("打劫成功,钱包增加:", userIncrMoney, wallet.GetWalletName()))
|
||||
ctx.SendChain(message.At(victimID), message.Text("保险公司对您进行了赔付,您实际损失:", victimDecrMoney, wallet.GetWalletName()))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/wallet"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/gg"
|
||||
"github.com/FloatTech/imgfactory"
|
||||
@ -84,8 +85,8 @@ func drawScore16(a *scdata) (image.Image, error) {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawStringAnchored(hourWord, 350, 280, 0, 0)
|
||||
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 350, 350, 0, 0)
|
||||
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 350, 400, 0, 0)
|
||||
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), 350, 350, 0, 0)
|
||||
canvas.DrawStringAnchored("当前"+wallet.GetWalletName()+":"+strconv.Itoa(a.score), 350, 400, 0, 0)
|
||||
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 350, 450, 0, 0)
|
||||
// draw Info(Time,etc.)
|
||||
getTime := time.Now().Format("2006-01-02 15:04:05")
|
||||
@ -161,8 +162,8 @@ func drawScore15(a *scdata) (image.Image, error) {
|
||||
if err = canvas.LoadFontFace(text.FontFile, float64(back.Bounds().Size().X)*0.04); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawString(a.nickname+fmt.Sprintf(" ATRI币+%d", a.inc), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.3)
|
||||
canvas.DrawString("当前ATRI币:"+strconv.FormatInt(int64(a.score), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.4)
|
||||
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)
|
||||
canvas.DrawString("当前"+wallet.GetWalletName()+":"+strconv.FormatInt(int64(a.score), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.4)
|
||||
canvas.DrawString("LEVEL:"+strconv.FormatInt(int64(a.rank), 10), float64(back.Bounds().Size().X)*0.1, float64(back.Bounds().Size().Y)*1.5)
|
||||
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)
|
||||
canvas.SetRGB255(150, 150, 150)
|
||||
@ -247,8 +248,8 @@ func drawScore17(a *scdata) (image.Image, error) {
|
||||
if err = canvas.ParseFontFace(data, 20); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), 40, float64(imgDY-90), 0, 0)
|
||||
canvas.DrawStringAnchored("当前ATRI币:"+strconv.Itoa(a.score), 40, float64(imgDY-60), 0, 0)
|
||||
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), 40, float64(imgDY-90), 0, 0)
|
||||
canvas.DrawStringAnchored("当前"+wallet.GetWalletName()+":"+strconv.Itoa(a.score), 40, float64(imgDY-60), 0, 0)
|
||||
canvas.DrawStringAnchored("LEVEL: "+strconv.Itoa(getrank(a.level)), 40, float64(imgDY-30), 0, 0)
|
||||
|
||||
// Draw Info(Time, etc.)
|
||||
@ -477,7 +478,7 @@ func customtext(a *scdata, fontdata []byte, cw, ch, aw float64, textcolor color.
|
||||
return
|
||||
}
|
||||
|
||||
canvas.DrawStringAnchored("ATRI币 + "+strconv.Itoa(a.inc), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh, 0, 0.5)
|
||||
canvas.DrawStringAnchored(wallet.GetWalletName()+" + "+strconv.Itoa(a.inc), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh, 0, 0.5)
|
||||
canvas.DrawStringAnchored("EXP + 1", ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4+tempfh+canvas.FontHeight(), 0, 1)
|
||||
|
||||
err = canvas.ParseFontFace(fontdata, (ch-sch)/2/4)
|
||||
@ -485,7 +486,7 @@ func customtext(a *scdata, fontdata []byte, cw, ch, aw float64, textcolor color.
|
||||
return
|
||||
}
|
||||
|
||||
canvas.DrawStringAnchored("你有 "+strconv.Itoa(a.score)+" 枚ATRI币", ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4*3, 0, 0.5)
|
||||
canvas.DrawStringAnchored("你有 "+strconv.Itoa(a.score)+" 枚"+wallet.GetWalletName(), ((cw-scw)-(cw/3-scw/2))/8, (ch-sch)/2+sch/4*3, 0, 0.5)
|
||||
|
||||
img = canvas.Image()
|
||||
return
|
||||
|
||||
@ -5,9 +5,11 @@ import (
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/wallet"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
@ -23,21 +25,35 @@ 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 = binary.BytesToString(content)
|
||||
} else {
|
||||
// 旧版本数据
|
||||
coinName = "ATRI币"
|
||||
}
|
||||
wallet.SetWalletName(coinName)
|
||||
}()
|
||||
en.OnFullMatch("查看我的钱包").SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
money := wallet.GetWalletOf(uid)
|
||||
ctx.SendChain(message.At(uid), message.Text("你的钱包当前有", money, "ATRI币"))
|
||||
ctx.SendChain(message.At(uid), message.Text("你的钱包当前有", money, wallet.GetWalletName()))
|
||||
})
|
||||
|
||||
en.OnFullMatch("查看钱包排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
|
||||
@ -62,7 +78,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
if len(st) == 0 {
|
||||
ctx.SendChain(message.Text("ERROR: 当前没人获取过ATRI币"))
|
||||
ctx.SendChain(message.Text("ERROR: 当前没人获取过", wallet.GetWalletName()))
|
||||
return
|
||||
} else if len(st) > 10 {
|
||||
st = st[:10]
|
||||
@ -98,7 +114,7 @@ func init() {
|
||||
}
|
||||
err = chart.BarChart{
|
||||
Font: font,
|
||||
Title: "ATRI币排名(1天只刷新1次)",
|
||||
Title: wallet.GetWalletName() + "排名(1天只刷新1次)",
|
||||
Background: chart.Style{
|
||||
Padding: chart.Box{
|
||||
Top: 40,
|
||||
@ -122,4 +138,15 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
||||
})
|
||||
en.OnPrefix("设置硬币名称", zero.OnlyToMe, zero.SuperUserPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
coinName := strings.TrimSpace(ctx.State["args"].(string))
|
||||
err := os.WriteFile(coinNameFile, binary.StringToBytes(coinName), 0644)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
wallet.SetWalletName(coinName)
|
||||
ctx.SendChain(message.Text("记住啦~"))
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user