mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
独立wallet插件 (#531)
This commit is contained in:
parent
913f01d69f
commit
a1f1016fb9
1
main.go
1
main.go
@ -132,6 +132,7 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vitsnyaru" // vits猫雷
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vitsnyaru" // vits猫雷
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
|
||||||
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wallet" // 钱包
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenben" // 文本指令大全
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenben" // 文本指令大全
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinAI" // 百度文心AI画图
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinAI" // 百度文心AI画图
|
||||||
|
|||||||
@ -54,11 +54,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
sdb = initialize(engine.DataFolder() + "score.db")
|
sdb = initialize(engine.DataFolder() + "score.db")
|
||||||
}()
|
}()
|
||||||
zero.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币"))
|
|
||||||
})
|
|
||||||
engine.OnFullMatch("签到").Limit(ctxext.LimitByUser).SetBlock(true).
|
engine.OnFullMatch("签到").Limit(ctxext.LimitByUser).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
@ -275,88 +270,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
||||||
})
|
})
|
||||||
engine.OnFullMatch("查看钱包排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
|
|
||||||
Handle(func(ctx *zero.Ctx) {
|
|
||||||
gid := strconv.FormatInt(ctx.Event.GroupID, 10)
|
|
||||||
today := time.Now().Format("20060102")
|
|
||||||
drawedFile := cachePath + gid + today + "walletRank.png"
|
|
||||||
if file.IsExist(drawedFile) {
|
|
||||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 无缓存获取群员列表
|
|
||||||
temp := ctx.GetThisGroupMemberListNoCache().Array()
|
|
||||||
usergroup := make([]int64, len(temp))
|
|
||||||
for i, info := range temp {
|
|
||||||
usergroup[i] = info.Get("user_id").Int()
|
|
||||||
}
|
|
||||||
// 获取钱包信息
|
|
||||||
st, err := wallet.GetGroupWalletOf(true, usergroup...)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(st) == 0 {
|
|
||||||
ctx.SendChain(message.Text("ERROR: 当前没人获取过ATRI币"))
|
|
||||||
return
|
|
||||||
} else if len(st) > 10 {
|
|
||||||
st = st[:10]
|
|
||||||
}
|
|
||||||
_, err = file.GetLazyData(text.FontFile, control.Md5File, true)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
b, err := os.ReadFile(text.FontFile)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
font, err := freetype.ParseFont(b)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
f, err := os.Create(drawedFile)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var bars []chart.Value
|
|
||||||
for _, v := range st {
|
|
||||||
if v.Money != 0 {
|
|
||||||
bars = append(bars, chart.Value{
|
|
||||||
Label: ctx.CardOrNickName(v.UID),
|
|
||||||
Value: float64(v.Money),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
err = chart.BarChart{
|
|
||||||
Font: font,
|
|
||||||
Title: "ATRI币排名(1天只刷新1次)",
|
|
||||||
Background: chart.Style{
|
|
||||||
Padding: chart.Box{
|
|
||||||
Top: 40,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
YAxis: chart.YAxis{
|
|
||||||
Range: &chart.ContinuousRange{
|
|
||||||
Min: 0,
|
|
||||||
Max: math.Ceil(bars[0].Value/10) * 10,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Height: 500,
|
|
||||||
BarWidth: 50,
|
|
||||||
Bars: bars,
|
|
||||||
}.Render(chart.PNG, f)
|
|
||||||
_ = f.Close()
|
|
||||||
if err != nil {
|
|
||||||
_ = os.Remove(drawedFile)
|
|
||||||
ctx.SendChain(message.Text("ERROR: ", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHourWord(t time.Time) string {
|
func getHourWord(t time.Time) string {
|
||||||
|
|||||||
125
plugin/wallet/wallet.go
Normal file
125
plugin/wallet/wallet.go
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
// Package wallet 钱包
|
||||||
|
package wallet
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/FloatTech/AnimeAPI/wallet"
|
||||||
|
"github.com/FloatTech/floatbox/file"
|
||||||
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
|
"github.com/golang/freetype"
|
||||||
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
en := control.Register("wallet", &ctrl.Options[*zero.Ctx]{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Brief: "钱包",
|
||||||
|
Help: "- 查看我的钱包\n- 查看钱包排名",
|
||||||
|
PrivateDataFolder: "wallet",
|
||||||
|
})
|
||||||
|
cachePath := en.DataFolder() + "cache/"
|
||||||
|
go func() {
|
||||||
|
_ = os.RemoveAll(cachePath)
|
||||||
|
err := os.MkdirAll(cachePath, 0755)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
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币"))
|
||||||
|
})
|
||||||
|
|
||||||
|
en.OnFullMatch("查看钱包排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true).
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
gid := strconv.FormatInt(ctx.Event.GroupID, 10)
|
||||||
|
today := time.Now().Format("20060102")
|
||||||
|
drawedFile := cachePath + gid + today + "walletRank.png"
|
||||||
|
if file.IsExist(drawedFile) {
|
||||||
|
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 无缓存获取群员列表
|
||||||
|
temp := ctx.GetThisGroupMemberListNoCache().Array()
|
||||||
|
usergroup := make([]int64, len(temp))
|
||||||
|
for i, info := range temp {
|
||||||
|
usergroup[i] = info.Get("user_id").Int()
|
||||||
|
}
|
||||||
|
// 获取钱包信息
|
||||||
|
st, err := wallet.GetGroupWalletOf(true, usergroup...)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(st) == 0 {
|
||||||
|
ctx.SendChain(message.Text("ERROR: 当前没人获取过ATRI币"))
|
||||||
|
return
|
||||||
|
} else if len(st) > 10 {
|
||||||
|
st = st[:10]
|
||||||
|
}
|
||||||
|
_, err = file.GetLazyData(text.FontFile, control.Md5File, true)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b, err := os.ReadFile(text.FontFile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
font, err := freetype.ParseFont(b)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f, err := os.Create(drawedFile)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var bars []chart.Value
|
||||||
|
for _, v := range st {
|
||||||
|
if v.Money != 0 {
|
||||||
|
bars = append(bars, chart.Value{
|
||||||
|
Label: ctx.CardOrNickName(v.UID),
|
||||||
|
Value: float64(v.Money),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = chart.BarChart{
|
||||||
|
Font: font,
|
||||||
|
Title: "ATRI币排名(1天只刷新1次)",
|
||||||
|
Background: chart.Style{
|
||||||
|
Padding: chart.Box{
|
||||||
|
Top: 40,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
YAxis: chart.YAxis{
|
||||||
|
Range: &chart.ContinuousRange{
|
||||||
|
Min: 0,
|
||||||
|
Max: math.Ceil(bars[0].Value/10) * 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Height: 500,
|
||||||
|
BarWidth: 50,
|
||||||
|
Bars: bars,
|
||||||
|
}.Render(chart.PNG, f)
|
||||||
|
_ = f.Close()
|
||||||
|
if err != nil {
|
||||||
|
_ = os.Remove(drawedFile)
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Image("file:///" + file.BOTPATH + "/" + drawedFile))
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user