From edceba76dac686ac0c59d72e8f795ac0af46cdfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sun, 29 Jun 2025 20:15:33 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E6=B3=A8=E9=94=80?= =?UTF-8?q?=E7=89=9B=E7=89=9B=E6=97=A0=E6=B3=95=E8=BF=9B=E8=A1=8C=E7=B4=AF?= =?UTF-8?q?=E5=8A=A0=E6=94=B6=E8=B4=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index ed618c4460..59f258509b 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -65,7 +65,7 @@ func init() { messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛拍卖行有以下牛牛"))) for _, info := range auction { msg := fmt.Sprintf("商品序号: %d\n牛牛原所属: %d\n牛牛价格: %d%s\n牛牛大小: %.2fcm", - info.ID+1, info.UserID, info.Money, wallet.GetWalletName(), info.Length) + info.ID, info.UserID, info.Money, wallet.GetWalletName(), info.Length) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text(msg))) } if id := ctx.Send(messages).ID(); id == 0 { @@ -90,7 +90,6 @@ func init() { ctx.SendChain(message.Text("ERROR: ", err)) return } - n-- msg, err := niu.Auction(gid, uid, n) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -151,7 +150,7 @@ func init() { var messages message.Message messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下"))) - for id := range propMap { + for id := 1; id <= 5; id++ { product := propMap[id] productInfo := fmt.Sprintf("商品%d\n商品名: %s\n商品价格: %dATRI币\n商品作用域: %s\n商品描述: %s\n使用次数:%d", id, product.name, product.cost, product.scope, product.description, product.count) @@ -380,6 +379,9 @@ func init() { ))) if c.Count >= 4 { + if c.Count == 6 { + return + } id := ctx.SendPrivateMessage(adduser, message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) if id == 0 { @@ -394,7 +396,7 @@ func init() { key := fmt.Sprintf("%d_%d", gid, uid) data, ok := register.Load(key) switch { - case !ok || time.Since(data.TimeLimit) > time.Hour*12: + case !ok || time.Since(data.TimeLimit) > time.Hour*24: data = &lastLength{ TimeLimit: time.Now(), Count: 1, @@ -404,6 +406,7 @@ func init() { ctx.SendChain(message.Text("你的钱不够你注销牛牛了,这次注销需要", data.Count*50, wallet.GetWalletName())) return } + data.Count++ } register.Store(key, data) msg, err := niu.Cancel(gid, uid) From 339cffcc5ea10c303cf3e397b0ff98758a84390f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Tue, 1 Jul 2025 11:07:05 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=9B=E7=89=9B?= =?UTF-8?q?=E5=95=86=E5=BA=97=E7=9A=84=E5=BE=AA=E7=8E=AF=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E4=B8=BA=E5=95=86=E5=93=81=E5=8F=98=E9=87=8F=E7=9A=84=E9=95=BF?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 59f258509b..013903ddfc 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -150,7 +150,7 @@ func init() { var messages message.Message messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下"))) - for id := 1; id <= 5; id++ { + for id := 1; id <= len(propMap); id++ { product := propMap[id] productInfo := fmt.Sprintf("商品%d\n商品名: %s\n商品价格: %dATRI币\n商品作用域: %s\n商品描述: %s\n使用次数:%d", id, product.name, product.cost, product.scope, product.description, product.count) From cf5c1f61f877b62a5635f6d8a79869a989e57d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sun, 24 Aug 2025 11:21:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=AF=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=B4=AD=E4=B9=B0=E5=95=86=E5=93=81=E6=95=B0?= =?UTF-8?q?=E9=87=8F=EF=BC=8C=E8=B0=83=E6=95=B4=E5=95=86=E5=93=81=E5=8D=95?= =?UTF-8?q?=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 79 +++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 013903ddfc..73f3663696 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -2,9 +2,11 @@ package niuniu import ( + "errors" "fmt" "math/rand" "strconv" + "strings" "time" "github.com/FloatTech/AnimeAPI/niu" @@ -18,12 +20,6 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" ) -type lastLength struct { - TimeLimit time.Time - Count int - Length float64 -} - var ( en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, @@ -47,8 +43,8 @@ var ( }) dajiaoLimiter = rate.NewManager[string](time.Second*90, 1) jjLimiter = rate.NewManager[string](time.Second*150, 1) - jjCount = syncx.Map[string, *lastLength]{} - register = syncx.Map[string, *lastLength]{} + jjCount = syncx.Map[string, *niu.Rm]{} + register = syncx.Map[string, *niu.Rm]{} ) func init() { @@ -103,15 +99,19 @@ func init() { en.OnFullMatch("出售牛牛", zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID + key := fmt.Sprintf("%d_%d", gid, uid) sell, err := niu.Sell(gid, uid) - if err != nil { + if errors.Is(err, niu.ErrCanceled) || errors.Is(err, niu.ErrNoNiuNiu) { + ctx.SendChain(message.Text(err)) + jjCount.Delete(key) + return + } else if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + // 数据库操作成功之后,及时删除残留的缓存 - key := fmt.Sprintf("%d_%d", gid, uid) - _, ok := jjCount.Load(key) - if ok { + if _, ok := jjCount.Load(key); ok { jjCount.Delete(key) } ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(sell)) @@ -140,29 +140,33 @@ func init() { cost int scope string description string - count int }{ - 1: {"伟哥", 300, "打胶", "可以让你打胶每次都增长", 5}, - 2: {"媚药", 300, "打胶", "可以让你打胶每次都减少", 5}, - 3: {"击剑神器", 500, "jj", "可以让你每次击剑都立于不败之地", 2}, - 4: {"击剑神稽", 500, "jj", "可以让你每次击剑都失败", 2}, + 1: {"伟哥", 100, "打胶", "可以让你打胶每次都增长"}, + 2: {"媚药", 100, "打胶", "可以让你打胶每次都减少"}, + 3: {"击剑神器", 300, "jj", "可以让你每次击剑都立于不败之地"}, + 4: {"击剑神稽", 300, "jj", "可以让你每次击剑都失败"}, } var messages message.Message - messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下"))) + messages = append(messages, ctxext.FakeSenderForwardNode(ctx, + message.Text("输入对应序号进行购买商品"), + message.Text( + "使用说明:\n"+ + "商品id-商品数量\n"+ + "如想购买10个伟哥\n"+ + "即:1-10"), + message.Text("牛牛商店当前售卖的物品如下"))) for id := 1; id <= len(propMap); id++ { product := propMap[id] - productInfo := fmt.Sprintf("商品%d\n商品名: %s\n商品价格: %dATRI币\n商品作用域: %s\n商品描述: %s\n使用次数:%d", - id, product.name, product.cost, product.scope, product.description, product.count) + productInfo := fmt.Sprintf("商品%d\n商品名: %s\n商品价格: %dATRI币\n商品作用域: %s\n商品描述: %s", + id, product.name, product.cost, product.scope, product.description) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text(productInfo))) } if id := ctx.Send(messages).ID(); id == 0 { ctx.Send(message.Text("发送商店失败")) return } - - ctx.SendChain(message.Text("输入对应序号进行购买商品")) - recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`^(\d+)$`)).Repeat() + recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`^(\d+)-(\d+)$`)).Repeat() defer cancel() timer := time.NewTimer(120 * time.Second) answer := "" @@ -174,13 +178,13 @@ func init() { return case r := <-recv: answer = r.Event.Message.String() - n, err := strconv.Atoi(answer) - if err != nil { - ctx.SendChain(message.Text("ERROR: ", err)) - return - } - if err = niu.Store(gid, uid, n); err != nil { + // 解析输入的商品ID和数量 + parts := strings.Split(answer, "-") + productID, _ := strconv.Atoi(parts[0]) + quantity, _ := strconv.Atoi(parts[1]) + + if err := niu.Store(gid, uid, productID, quantity); err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return } @@ -227,7 +231,7 @@ func init() { return } - if err := niu.Redeem(gid, uid, last.Length); err != nil { + if err := niu.Redeem(gid, uid, *last); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } @@ -337,7 +341,7 @@ func init() { } uid := ctx.Event.UserID gid := ctx.Event.GroupID - msg, length, err := niu.JJ(gid, uid, adduser, patternParsed[0].Text()[1]) + msg, length, niuID, err := niu.JJ(gid, uid, adduser, patternParsed[0].Text()[1]) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) jjLimiter.Delete(fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)) @@ -346,24 +350,27 @@ func init() { ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(msg)) j := fmt.Sprintf("%d_%d", gid, adduser) count, ok := jjCount.Load(j) - var c lastLength + var c niu.Rm // 按照最后一次被 jj 时的时间计算,超过60分钟则重置 if !ok { // 第一次被 jj - c = lastLength{ + c = niu.Rm{ + NiuID: niuID, TimeLimit: time.Now(), Count: 1, Length: length, } } else { - c = lastLength{ + c = niu.Rm{ + NiuID: niuID, TimeLimit: time.Now(), Count: count.Count + 1, Length: count.Length, } // 超时了,重置 if time.Since(c.TimeLimit) > time.Hour { - c = lastLength{ + c = niu.Rm{ + NiuID: niuID, TimeLimit: time.Now(), Count: 1, Length: length, @@ -397,7 +404,7 @@ func init() { data, ok := register.Load(key) switch { case !ok || time.Since(data.TimeLimit) > time.Hour*24: - data = &lastLength{ + data = &niu.Rm{ TimeLimit: time.Now(), Count: 1, }