From a29bbec1daedd10a825b989636b37782bacd2c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:52:58 +0800 Subject: [PATCH 01/35] Update main.go --- plugin/niuniu/main.go | 110 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 15 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 8d75b9d594..56312ad219 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -3,19 +3,26 @@ package niuniu import ( "fmt" - "math/rand" - "strconv" - "strings" - "time" - + "github.com/FloatTech/AnimeAPI/wallet" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/wdvxdr1123/ZeroBot/message" + "math/rand" + "strconv" + "strings" + "sync" + "time" ) +type lastLength struct { + TimeLimit time.Time + Count int + Length float64 +} + var ( en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, @@ -31,9 +38,52 @@ var ( }) dajiaoLimiter = rate.NewManager[string](time.Second*90, 1) jjLimiter = rate.NewManager[string](time.Second*150, 1) + jjCount = make(map[string]lastLength) + lock sync.RWMutex ) func init() { + en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + last, ok := jjCount[fmt.Sprintf("%d_%d", gid, uid)] + if !ok { + ctx.SendChain(message.Text("你还没有被厥呢")) + return + } + if time.Now().Sub(last.TimeLimit) > time.Minute*30 { + ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!")) + lock.Lock() + delete(jjCount, fmt.Sprintf("%d_%d", gid, uid)) + lock.Unlock() + return + } + if last.Count < 6 { + ctx.SendChain(message.Text("你还没有被厥够6次呢,不能赎牛牛")) + return + } + money := wallet.GetWalletOf(uid) + if money < 100 { + ctx.SendChain(message.Text("赎牛牛需要100ATRI币,快去赚钱吧")) + return + } + err := wallet.InsertWalletOf(uid, -100) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + u := &userInfo{ + UID: uid, + Length: last.Length, + UserCount: 0, + } + err = db.insertniuniu(u, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2f", last.Length))) + }) en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID niuniuList, err := db.readAllTable(gid) @@ -47,8 +97,8 @@ func init() { return } var messages strings.Builder - messages.WriteString("牛子长度排行\n") - for i, user := range niuniuList.sort(true) { + messages.WriteString("牛子长度排行榜\n") + for i, user := range m.sort(true) { messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1, ctx.CardOrNickName(user.UID), user.Length)) } @@ -71,7 +121,7 @@ func init() { } var messages strings.Builder messages.WriteString("牛牛深度排行榜\n") - for i, user := range niuniuList.sort(false) { + for i, user := range m.sort(false) { messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1, ctx.CardOrNickName(user.UID), user.Length)) } @@ -130,8 +180,9 @@ func init() { } messages, f := generateRandomStingTwo(niuniu) u := userInfo{ - UID: uid, - Length: f, + UID: uid, + Length: f, + UserCount: 0, } ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { @@ -146,14 +197,14 @@ func init() { ctx.SendChain(message.Text("你已经注册过了")) return } - // 获取初始长度 + //获取初始长度 long := db.randLength() u := userInfo{ UID: uid, Length: long, UserCount: 0, } - // 添加数据进入表 + //添加数据进入表 err := db.insertniuniu(&u, gid) if err != nil { err = db.createGIDTable(gid) @@ -210,17 +261,46 @@ func init() { return } fencingResult, f, f1 := fencing(myniuniu, adduserniuniu) - err = db.insertniuniu(&userInfo{UID: uid, Length: f}, gid) + err = db.insertniuniu(&userInfo{UID: uid, Length: f, UserCount: 0}, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid) + err = db.insertniuniu(&userInfo{UID: adduser, Length: f1, UserCount: 0}, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - ctx.SendChain(message.At(uid), message.Text(fencingResult)) + ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) + lock.RLock() + count, ok := jjCount[fmt.Sprintf("%d_%d", gid, adduser)] + lock.RUnlock() + var c lastLength + if !ok { + c = lastLength{ + TimeLimit: time.Now(), + Count: 1, + Length: adduserniuniu, + } + } else { + c = lastLength{ + TimeLimit: c.TimeLimit, + Count: count.Count + 1, + Length: count.Length, + } + } + lock.Lock() + jjCount[fmt.Sprintf("%d_%d", gid, adduser)] = c + lock.Unlock() + if c.Count > 5 { + ctx.SendChain(message.Text(fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count))) + id := ctx.SendPrivateMessage(adduser, + message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) + if id == 0 { + ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) + } + } + }) en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID From c22079e38b7dba78812e2a696d298cf51163c07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:53:18 +0800 Subject: [PATCH 02/35] Update model.go --- plugin/niuniu/model.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 153335e01b..44152a1366 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -2,16 +2,15 @@ package niuniu import ( + fcext "github.com/FloatTech/floatbox/ctxext" + sql "github.com/FloatTech/sqlite" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" "math/rand" "sort" "strconv" "sync" "time" - - fcext "github.com/FloatTech/floatbox/ctxext" - sql "github.com/FloatTech/sqlite" - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" ) type model struct { @@ -24,6 +23,7 @@ type userInfo struct { Length float64 UserCount int } + type users []*userInfo var ( @@ -39,21 +39,21 @@ var ( }) ) -func (m users) positive() []userInfo { - var m1 []userInfo +func (m users) positive() users { + var m1 []*userInfo for _, i2 := range m { if i2.Length > 0 { - m1 = append(m1, *i2) + m1 = append(m1, i2) } } return m1 } -func (m users) negative() []userInfo { - var m1 []userInfo +func (m users) negative() users { + var m1 []*userInfo for _, i2 := range m { if i2.Length <= 0 { - m1 = append(m1, *i2) + m1 = append(m1, i2) } } return m1 @@ -61,7 +61,7 @@ func (m users) negative() []userInfo { func (m users) sort(isDesc bool) users { t := func(i, j int) bool { - return m[i].UserCount < m[j].UserCount + return m[i].Length < m[j].Length } if isDesc { t = func(i, j int) bool { From 78e9d1aa0966fb54f798cbf35af04e09e785a488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:53:41 +0800 Subject: [PATCH 03/35] Update utils.go --- plugin/niuniu/utils.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 85a7ff8989..96d462107d 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -107,27 +107,26 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) { switch { case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20: oppoLength *= 0.85 - change := -math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength)) + change := math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength)) myLength += change - return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", myLength), myLength, oppoLength + return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20: oppoLength *= 0.85 - change := -math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength)) + change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength)) myLength += change - return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength + return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength-oppoLength), myLength - oppoLength, oppoLength case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20: myLength *= 0.85 - change := math.Min(math.Abs(lossLimit*oppoLength), math.Abs(1.5*oppoLength)) + change := oppoLength * 0.7 oppoLength -= change + myLength -= change return fmt.Sprintf("你身为魅魔诱惑了对方,吞噬了对方部分长度!当前长度%.2fcm!", myLength), myLength, oppoLength case myLength >= 100 && oppoLength > 0 && 10 < probability && probability <= 20: myLength *= 0.85 - change := math.Min(math.Abs(devourLimit*oppoLength), math.Abs(1.5*oppoLength)) - oppoLength += change + oppoLength -= 0.8 * myLength return fmt.Sprintf("你以牛头人的荣誉摧毁了对方的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength - default: return determineResultBySkill(myLength, oppoLength) } @@ -166,6 +165,7 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo return fmt.Sprintf("哦吼!?你的牛牛在长大欸!长大了%.2fcm!", reduce), myLength, oppoLength } return fmt.Sprintf("你以绝对的长度让对方屈服了呢!你的长度增加%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength + } myLength -= reduce oppoLength += 0.8 * reduce @@ -173,6 +173,7 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo return fmt.Sprintf("哦吼!?看来你的牛牛因为击剑而凹进去了呢🤣🤣🤣!凹进去了%.2fcm!", reduce), myLength, oppoLength } return fmt.Sprintf("对方以绝对的长度让你屈服了呢!你的长度减少%.2fcm,当前长度%.2fcm!", reduce, myLength), myLength, oppoLength + } // fence From 4f9c58f55e158b64d940f4947d524fe89e24e276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:54:28 +0800 Subject: [PATCH 04/35] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7782f407b8..d3f5fbc0a0 100644 --- a/README.md +++ b/README.md @@ -1037,6 +1037,8 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] jj[@xxx] +- [x] 赎牛牛 + - [x] 注册牛牛 - [x] 注销牛牛 From 66afee9f044e411fe5afcf49ba55afb03a5d6bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sat, 31 Aug 2024 15:57:33 +0800 Subject: [PATCH 05/35] Update main.go --- 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 56312ad219..183b98cea1 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -82,7 +82,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2f", last.Length))) + ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length))) }) en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID From be5ec000f92f795b17410d8b9c98f12a0209f7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 1 Sep 2024 22:57:17 +0800 Subject: [PATCH 06/35] Update main.go --- plugin/niuniu/main.go | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 183b98cea1..f5dd9e1f25 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -4,17 +4,18 @@ package niuniu import ( "fmt" "github.com/FloatTech/AnimeAPI/wallet" + "math/rand" + "strconv" + "strings" + "sync" + "time" + ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/wdvxdr1123/ZeroBot/message" - "math/rand" - "strconv" - "strings" - "sync" - "time" ) type lastLength struct { @@ -38,24 +39,22 @@ var ( }) dajiaoLimiter = rate.NewManager[string](time.Second*90, 1) jjLimiter = rate.NewManager[string](time.Second*150, 1) - jjCount = make(map[string]lastLength) - lock sync.RWMutex + jjCount = sync.Map{} ) func init() { en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID - last, ok := jjCount[fmt.Sprintf("%d_%d", gid, uid)] + l, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid)) + last := l.(lastLength) if !ok { ctx.SendChain(message.Text("你还没有被厥呢")) return } - if time.Now().Sub(last.TimeLimit) > time.Minute*30 { + if time.Since(last.TimeLimit) > time.Minute*30 { ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!")) - lock.Lock() - delete(jjCount, fmt.Sprintf("%d_%d", gid, uid)) - lock.Unlock() + jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } if last.Count < 6 { @@ -180,9 +179,8 @@ func init() { } messages, f := generateRandomStingTwo(niuniu) u := userInfo{ - UID: uid, - Length: f, - UserCount: 0, + UID: uid, + Length: f, } ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { @@ -197,14 +195,14 @@ func init() { ctx.SendChain(message.Text("你已经注册过了")) return } - //获取初始长度 + // 获取初始长度 long := db.randLength() u := userInfo{ UID: uid, Length: long, UserCount: 0, } - //添加数据进入表 + // 添加数据进入表 err := db.insertniuniu(&u, gid) if err != nil { err = db.createGIDTable(gid) @@ -272,9 +270,9 @@ func init() { return } ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) - lock.RLock() - count, ok := jjCount[fmt.Sprintf("%d_%d", gid, adduser)] - lock.RUnlock() + j := fmt.Sprintf("%d_%d", gid, adduser) + cou, ok := jjCount.Load(j) + count := cou.(lastLength) var c lastLength if !ok { c = lastLength{ @@ -289,9 +287,7 @@ func init() { Length: count.Length, } } - lock.Lock() - jjCount[fmt.Sprintf("%d_%d", gid, adduser)] = c - lock.Unlock() + jjCount.Store(j, c) if c.Count > 5 { ctx.SendChain(message.Text(fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count))) id := ctx.SendPrivateMessage(adduser, From 22e2447720010a049948b85abf09c169d4cdd4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 1 Sep 2024 22:59:09 +0800 Subject: [PATCH 07/35] Update model.go --- plugin/niuniu/model.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 44152a1366..e9ce5a1b45 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -2,15 +2,16 @@ package niuniu import ( - fcext "github.com/FloatTech/floatbox/ctxext" - sql "github.com/FloatTech/sqlite" - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" "math/rand" "sort" "strconv" "sync" "time" + + fcext "github.com/FloatTech/floatbox/ctxext" + sql "github.com/FloatTech/sqlite" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" ) type model struct { From 05a28c9630d15cf684dfd2b33c212f2565ba4fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Mon, 2 Sep 2024 13:34:34 +0800 Subject: [PATCH 08/35] Update main.go --- plugin/niuniu/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index f5dd9e1f25..6ece9b500d 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -81,6 +81,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } + jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length))) }) en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { From fa0c9d8eb4843a3cf67bcfd96e550c2d8117921a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:02:47 +0800 Subject: [PATCH 09/35] Update main.go --- plugin/niuniu/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 6ece9b500d..f2920070a0 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -291,10 +291,13 @@ func init() { jjCount.Store(j, c) if c.Count > 5 { ctx.SendChain(message.Text(fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count))) - id := ctx.SendPrivateMessage(adduser, + // 保证只发送一次 + if c. Count < 7 { + id := ctx.SendPrivateMessage(adduser, message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) - if id == 0 { + if id == 0 { ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) + } } } From 83ee8b6334b39a83ede075de6d216bfc1e2fccbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:47:22 +0800 Subject: [PATCH 10/35] Update main.go --- plugin/niuniu/main.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index f2920070a0..4b47b03b21 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -3,16 +3,16 @@ package niuniu import ( "fmt" - "github.com/FloatTech/AnimeAPI/wallet" "math/rand" "strconv" "strings" - "sync" "time" + "github.com/FloatTech/AnimeAPI/wallet" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" + "github.com/RomiChan/syncx" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/wdvxdr1123/ZeroBot/message" @@ -39,15 +39,14 @@ var ( }) dajiaoLimiter = rate.NewManager[string](time.Second*90, 1) jjLimiter = rate.NewManager[string](time.Second*150, 1) - jjCount = sync.Map{} + jjCount = syncx.Map[string, *lastLength]{} ) func init() { en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID - l, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid)) - last := l.(lastLength) + last, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid)) if !ok { ctx.SendChain(message.Text("你还没有被厥呢")) return @@ -272,8 +271,7 @@ func init() { } ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) j := fmt.Sprintf("%d_%d", gid, adduser) - cou, ok := jjCount.Load(j) - count := cou.(lastLength) + count, ok := jjCount.Load(j) var c lastLength if !ok { c = lastLength{ @@ -288,19 +286,18 @@ func init() { Length: count.Length, } } - jjCount.Store(j, c) + jjCount.Store(j, &c) if c.Count > 5 { - ctx.SendChain(message.Text(fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count))) - // 保证只发送一次 - if c. Count < 7 { + ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), + fmt.Sprintf("你们不要再找ta🤺啦!")}))) + if c.Count < 7 { id := ctx.SendPrivateMessage(adduser, - message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) + message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) if id == 0 { - ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) + ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) } } } - }) en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID From dd676ad577298fc35c65e2a6898d56c83d415365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:09:15 +0800 Subject: [PATCH 11/35] Update main.go --- 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 4b47b03b21..8d1fd54c6b 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -289,7 +289,7 @@ func init() { jjCount.Store(j, &c) if c.Count > 5 { ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), - fmt.Sprintf("你们不要再找ta🤺啦!")}))) + "你们不要再找ta🤺啦!"}))) if c.Count < 7 { id := ctx.SendPrivateMessage(adduser, message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) From 85ca08afa7486364ce9383733171f9ddf69114a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Tue, 3 Sep 2024 22:55:50 +0800 Subject: [PATCH 12/35] Update main.go --- plugin/niuniu/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 8d1fd54c6b..53f82865be 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -29,6 +29,7 @@ var ( DisableOnDefault: false, Brief: "牛牛大作战", Help: "- 打胶\n" + + "- 赎牛牛 (cd:30分钟)\n" + "- 注册牛牛\n" + "- 注销牛牛\n" + "- 查看我的牛牛\n" + From 2cde59d54875998a6ac854e8abf0911204b36079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:13:23 +0800 Subject: [PATCH 13/35] Update main.go --- plugin/niuniu/main.go | 218 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 206 insertions(+), 12 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 008143aebc..ee189f7374 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -24,16 +24,22 @@ type lastLength struct { Length float64 } +type propsCount struct { + Count int + TimeLimit time.Time +} + var ( en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{ DisableOnDefault: false, Brief: "牛牛大作战", Help: "- 打胶\n" + - "- 赎牛牛 (cd:30分钟)\n" + + "- jj@xxx\n" + "- 注册牛牛\n" + + "- 赎牛牛(cd:30分钟)\n" + + "- 牛牛商店\n" + "- 注销牛牛\n" + "- 查看我的牛牛\n" + - "- jj@xxx\n" + "- 牛子长度排行\n" + "- 牛子深度排行\n", PrivateDataFolder: "niuniu", @@ -41,9 +47,93 @@ var ( dajiaoLimiter = rate.NewManager[string](time.Second*90, 1) jjLimiter = rate.NewManager[string](time.Second*150, 1) jjCount = syncx.Map[string, *lastLength]{} + prop = syncx.Map[string, *propsCount]{} ) func init() { + en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.GroupID + var messages message.Message + messages = append(messages, message.Text("牛牛商店当前售卖的物品如下")) + messages = append(messages, + ctxext.FakeSenderForwardNode(ctx, + message.Text(fmt.Sprintf("商品1\n商品名:伟哥\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都增长,有效5次")))) + messages = append(messages, + ctxext.FakeSenderForwardNode(ctx, + message.Text(fmt.Sprintf("商品2\n商品名:媚药\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都减少,有效5次")))) + messages = append(messages, + ctxext.FakeSenderForwardNode(ctx, + message.Text(fmt.Sprintf("商品3\n商品名:击剑神器\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都立于不败之地,有效2次")))) + messages = append(messages, + ctxext.FakeSenderForwardNode(ctx, + message.Text(fmt.Sprintf("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次")))) + if id := ctx.Send(messages).ID(); id == 0 { + ctx.Send(message.Text("发送商店失败")) + } + ctx.SendChain(message.Text("输入对应序号进行购买商品")) + recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`(/d+)`)).Repeat() + defer cancel() + timer := time.NewTimer(120 * time.Second) + for { + select { + case <-timer.C: + ctx.SendChain(message.At(uid), message.Text("超时,已自动取消")) + return + case r := <-recv: + answer := r.Event.Message.String() + n, err := strconv.Atoi(answer) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + info, err := db.findniuniu(gid, uid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + var ( + money int + u *userInfo + ) + switch n { + case 1: + money = 300 + u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} + case 2: + money = 300 + u = &userInfo{UID: uid, Philter: info.Philter + 5} + case 3: + money = 500 + u = &userInfo{UID: uid, Artifact: info.Artifact + 2} + case 4: + money = 500 + u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} + default: + ctx.SendChain(message.Text("无效的选项")) + return + } + + if wallet.GetWalletOf(uid) < money { + ctx.SendChain(message.Text("你还没有足够的ATRI币呢,不能购买")) + return + } + err = wallet.InsertWalletOf(uid, -money) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + + err = db.insertniuniu(u, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + + ctx.SendChain(message.Text("购买成功!")) + } + } + }) en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID @@ -63,10 +153,10 @@ func init() { } money := wallet.GetWalletOf(uid) if money < 100 { - ctx.SendChain(message.Text("赎牛牛需要100ATRI币,快去赚钱吧")) + ctx.SendChain(message.Text("赎牛牛需要150ATRI币,快去赚钱吧")) return } - err := wallet.InsertWalletOf(uid, -100) + err := wallet.InsertWalletOf(uid, -150) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -133,11 +223,12 @@ func init() { en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID gid := ctx.Event.GroupID - niuniu, err := db.findniuniu(gid, uid) + i, err := db.findniuniu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢不能查看!")) return } + niuniu := i.Length var result strings.Builder sexLong := "长" sex := "♂️" @@ -172,17 +263,54 @@ func init() { // 获取群号和用户ID gid := ctx.Event.GroupID uid := ctx.Event.UserID + t := fmt.Sprintf("%d_%d", gid, uid) + updateMap(t, false) niuniu, err := db.findniuniu(gid, uid) if err != nil { ctx.SendChain(message.Text("请先注册牛牛!")) dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - messages, f := generateRandomStingTwo(niuniu) - u := userInfo{ - UID: uid, - Length: f, + var ( + messages string + f float64 + u userInfo + ) + load, ok := prop.Load(fmt.Sprintf(t)) + if ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8 { + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + } else { + switch { + case niuniu.WeiGe > 0: + messages, f = useWeiGe(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + WeiGe: niuniu.WeiGe - 1, + } + updateMap(t, true) + case niuniu.Philter > 0: + messages, f = usePhilter(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Philter: niuniu.Philter - 1, + } + updateMap(t, true) + default: + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + } } + ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -243,6 +371,8 @@ func init() { } uid := ctx.Event.UserID gid := ctx.Event.GroupID + t := fmt.Sprintf("%d_%d", gid, uid) + updateMap(t, false) myniuniu, err := db.findniuniu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!")) @@ -260,8 +390,39 @@ func init() { jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - fencingResult, f, f1 := fencing(myniuniu, adduserniuniu) - err = db.insertniuniu(&userInfo{UID: uid, Length: f, UserCount: 0}, gid) + var ( + fencingResult string + f float64 + f1 float64 + u userInfo + ) + v, ok := prop.Load(t) + if ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8 { + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + } else { + switch { + case myniuniu.Artifact > 0: + fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Artifact: myniuniu.Artifact - 1, + } + updateMap(t, true) + case myniuniu.ShenJi > 0: + fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Artifact: myniuniu.ShenJi - 1, + } + updateMap(t, true) + default: + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + } + } + err = db.insertniuniu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -279,7 +440,7 @@ func init() { c = lastLength{ TimeLimit: time.Now(), Count: 1, - Length: adduserniuniu, + Length: adduserniuniu.Length, } } else { c = lastLength{ @@ -287,7 +448,15 @@ func init() { Count: count.Count + 1, Length: count.Length, } + if time.Since(c.TimeLimit) > time.Minute*30 { + c = lastLength{ + TimeLimit: time.Now(), + Count: 1, + Length: adduserniuniu.Length, + } + } } + jjCount.Store(j, &c) if c.Count > 5 { ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), @@ -321,3 +490,28 @@ func init() { func randomChoice(options []string) string { return options[rand.Intn(len(options))] } + +func updateMap(t string, d bool) { + + value, ok := prop.Load(t) + if !d { + if time.Since(value.TimeLimit) > time.Minute*8 { + prop.Delete(t) + } + return + } + if ok { + prop.Store(t, &propsCount{ + Count: value.Count + 1, + TimeLimit: value.TimeLimit, + }) + } else { + prop.Store(t, &propsCount{ + Count: 1, + TimeLimit: time.Now(), + }) + } + if time.Since(value.TimeLimit) > time.Minute*8 { + prop.Delete(t) + } +} From e06ece663f02ee8fcde49ba5c636e9715ae0cb75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:17:53 +0800 Subject: [PATCH 14/35] Update utils.go --- plugin/niuniu/utils.go | 113 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 14 deletions(-) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 96d462107d..d37d32bd4e 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -5,9 +5,78 @@ import ( "fmt" "math" "math/rand" - "time" ) +func useWeiGe(niuniu float64) (string, float64) { + reduce := math.Abs(hitGlue(niuniu)) + niuniu += reduce + return randomChoice([]string{ + fmt.Sprintf("哈哈,你这一用道具,牛牛就像是被激发了潜能,增加了%.2fcm!看来今天是个大日子呢!", reduce), + fmt.Sprintf("你这是用了什么神奇的道具?牛牛竟然增加了%.2fcm,简直是牛气冲天!", reduce), + fmt.Sprintf("“使用道具后,你的牛牛就像是开启了加速模式,一下增加了%.2fcm,这成长速度让人惊叹!", reduce), + }), niuniu +} + +func usePhilter(niuniu float64) (string, float64) { + reduce := math.Abs(hitGlue(niuniu)) + niuniu -= reduce + return randomChoice([]string{ + fmt.Sprintf("你使用媚药,咿呀咿呀一下使当前长度发生了一些变化,当前长度%.2f", niuniu), + fmt.Sprintf("看来你追求的是‘微观之美’,故意使用道具让牛牛凹进去了%.2fcm!", reduce), + fmt.Sprintf("‘缩小奇迹’在你身上发生了,牛牛凹进去了%.2fcm,你的选择真是独特!", reduce), + }), niuniu +} + +func useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { + difference := myLength - adduserniuniu + var ( + change float64 + ) + if difference > 0 { + change = hitGlue(myLength + adduserniuniu) + } else { + change = hitGlue((myLength + adduserniuniu) / 2) + } + myLength += change + return randomChoice([]string{ + fmt.Sprintf("凭借神秘道具的力量,你让对方在你的长度面前俯首称臣!你的长度增加了%.2fcm,当前长度达到了%.2fcm", change, myLength), + fmt.Sprintf("神器在手,天下我有!你使用道具后,长度猛增%.2fcm,现在的总长度是%.2fcm,无人能敌!", change, myLength), + fmt.Sprintf("这就是道具的魔力!你轻松增加了%.2fcm,让对手望尘莫及,当前长度为%.2fcm!", change, myLength), + fmt.Sprintf("道具一出,谁与争锋!你的长度因道具而增长%.2fcm,现在的长度是%.2fcm,霸气尽显!", change, myLength), + fmt.Sprintf("使用道具的你,如同获得神助!你的长度增长了%.2fcm,达到%.2fcm的惊人长度,胜利自然到手!", change, myLength), + }), myLength, adduserniuniu - change/1.3 +} + +func useShenJi(myLength, adduserniuniu float64) (string, float64, float64) { + difference := myLength - adduserniuniu + var ( + change float64 + ) + if difference > 0 { + change = hitGlue(myLength + adduserniuniu) + } else { + change = hitGlue((myLength + adduserniuniu) / 2) + } + myLength -= change + var r string + if myLength > 0 { + r = randomChoice([]string{ + fmt.Sprintf("哦吼!?看来你的牛牛因为使用了神秘道具而缩水了呢🤣🤣🤣!缩小了%.2fcm!", change), + fmt.Sprintf("哈哈,看来这个道具有点儿调皮,让你的长度缩水了%.2fcm!现在你的长度是%.2fcm,下次可得小心使用哦!", change, myLength), + fmt.Sprintf("使用道具后,你的牛牛似乎有点儿害羞,缩水了%.2fcm!现在的长度是%.2fcm,希望下次它能挺直腰板!", change, myLength), + fmt.Sprintf("哎呀,这个道具的效果有点儿意外,你的长度减少了%.2fcm,现在只有%.2fcm了!下次选道具可得睁大眼睛!", change, myLength), + }) + } else { + r = randomChoice([]string{ + fmt.Sprintf("哦哟,小姐姐真是玩得一手好游戏,使用道具后数值又降低了%.2fcm,小巧得更显魅力!", change), + fmt.Sprintf("看来小姐姐喜欢更加精致的风格,使用道具后,数值减少了%.2fcm,更加迷人了!", change), + fmt.Sprintf("小姐姐的每一次变化都让人惊喜,使用道具后,数值减少了%.2fcm,更加优雅动人!", change), + fmt.Sprintf("小姐姐这是在展示什么是真正的精致小巧,使用道具后,数值减少了%.2fcm,美得不可方物!", change), + }) + } + return r, myLength, adduserniuniu + 0.7*change +} + func generateRandomStingTwo(niuniu float64) (string, float64) { probability := rand.Intn(100 + 1) reduce := math.Abs(hitGlue(niuniu)) @@ -99,7 +168,6 @@ func generateRandomString(niuniu float64) string { // fencing 击剑对决逻辑,返回对决结果和myLength的变化值 func fencing(myLength, oppoLength float64) (string, float64, float64) { - lossLimit := 0.25 devourLimit := 0.27 probability := rand.Intn(100) + 1 @@ -107,26 +175,28 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) { switch { case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20: oppoLength *= 0.85 - change := math.Min(math.Abs(lossLimit*myLength), math.Abs(1.5*myLength)) - myLength += change + change := hitGlue(oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength))) + myLength = change return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength + case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20: oppoLength *= 0.85 change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength)) myLength += change - return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength-oppoLength), myLength - oppoLength, oppoLength + return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20: myLength *= 0.85 - change := oppoLength * 0.7 + change := hitGlue(myLength+oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength))) oppoLength -= change myLength -= change return fmt.Sprintf("你身为魅魔诱惑了对方,吞噬了对方部分长度!当前长度%.2fcm!", myLength), myLength, oppoLength case myLength >= 100 && oppoLength > 0 && 10 < probability && probability <= 20: - myLength *= 0.85 - oppoLength -= 0.8 * myLength + myLength -= oppoLength + oppoLength = 0.01 return fmt.Sprintf("你以牛头人的荣誉摧毁了对方的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength + default: return determineResultBySkill(myLength, oppoLength) } @@ -146,7 +216,7 @@ func calculateWinProbability(heightA, heightB float64) float64 { if heightA > heightB { pA = 0.7 + 0.2*(heightA-heightB)/heightA } else { - pA = 0.6 - 0.2*(heightB-heightA)/heightB + pA = 0.7 - 0.2*(heightB-heightA)/heightB } heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB) reductionRate := 0.1 * (heightRatio - 1) @@ -178,13 +248,28 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo // fence func fence(rd float64) float64 { - rd -= float64(time.Now().UnixNano() % 10) - if rd > 1000000 { - return rd - rand.Float64()*rd + r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd) + if rand.Intn(2) == 1 { + return rd - rand.Float64()*r } - return float64(int(rd * rand.Float64())) + return float64(int(r * rand.Float64())) } func hitGlue(l float64) float64 { - return rand.Float64() * math.Log2(l) / 2 + if l == 0 { + l = 0.1 + } + l = math.Abs(l) + switch { + case l > 1 && l <= 10: + return rand.Float64() * math.Log2(l) + case 10 < l && l <= 100: + return rand.Float64() * math.Log2(l*1.5) / 2 + case 100 < l && l <= 1000: + return rand.Float64() * math.Log10(l*1.5) / 2 + case l > 1000: + return rand.Float64() * math.Log10(l) / 2 + default: + return rand.Float64() + } } From 8b862fa245fb58f5b816434452adc75c9cf58523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:18:17 +0800 Subject: [PATCH 15/35] Update model.go --- plugin/niuniu/model.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index e9ce5a1b45..a4374a3212 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -23,6 +23,10 @@ type userInfo struct { UID int64 Length float64 UserCount int + WeiGe int // 伟哥 + Philter int // 媚药 + Artifact int // 击剑神器 + ShenJi int // 击剑神稽 } type users []*userInfo @@ -93,12 +97,12 @@ func (db *model) createGIDTable(gid int64) error { return db.sql.Create(strconv.FormatInt(gid, 10), &userInfo{}) } -func (db *model) findniuniu(gid, uid int64) (float64, error) { +func (db *model) findniuniu(gid, uid int64) (userInfo, error) { db.RLock() defer db.RUnlock() u := userInfo{} err := db.sql.Find(strconv.FormatInt(gid, 10), &u, "where UID = "+strconv.FormatInt(uid, 10)) - return u.Length, err + return u, err } func (db *model) insertniuniu(u *userInfo, gid int64) error { From d2f4a29ff047ea0d5f977571a71eea8167c098c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:21:03 +0800 Subject: [PATCH 16/35] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d3f5fbc0a0..e5de87d8ab 100644 --- a/README.md +++ b/README.md @@ -1039,6 +1039,8 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 赎牛牛 +- [x] 牛牛商店 + - [x] 注册牛牛 - [x] 注销牛牛 From 4e222f40aa97fee8b112cdba9ba524450e143bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <158024940+xyy0411@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:23:04 +0800 Subject: [PATCH 17/35] Update main.go --- plugin/niuniu/main.go | 123 ++++++++++++++++++++++++++---------------- 1 file changed, 78 insertions(+), 45 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index ee189f7374..c473d016f9 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -50,6 +50,30 @@ var ( prop = syncx.Map[string, *propsCount]{} ) +/*func 渡劫成功与否(u userInfo, product bool) { + daojieSuccessRates := map[int]float64{ + 1: 0.8, //练气一层 + 2: 0.75, //练气二层 + 3: 0.7, //练气三层 + 4: 0.65, //练气四层 + 5: 0.6, //练气五层 + 6: 0.55, //练气六层 + 7: 0.5, //练气七层 + 8: 0.45, //练气八层 + 9: 0.4, //练气九层 + 10: 0.35, //金丹一层 + 11: 0.3, //金丹二层 + 12: 0.25, //金丹三层 + 13: 0.2, //金丹四层 + 14: 0.15, //金丹五层 + 15: 0.1, //金丹六层 + 16: 0.08, //金丹七层 + 17: 0.06, //金丹八层 + 18: 0.04, //金丹九层 + } + +}*/ + func init() { en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID @@ -58,16 +82,16 @@ func init() { messages = append(messages, message.Text("牛牛商店当前售卖的物品如下")) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, - message.Text(fmt.Sprintf("商品1\n商品名:伟哥\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都增长,有效5次")))) + message.Text("商品1\n商品名:伟哥\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都增长,有效5次"))) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, - message.Text(fmt.Sprintf("商品2\n商品名:媚药\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都减少,有效5次")))) + message.Text("商品2\n商品名:媚药\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都减少,有效5次"))) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, - message.Text(fmt.Sprintf("商品3\n商品名:击剑神器\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都立于不败之地,有效2次")))) + message.Text("商品3\n商品名:击剑神器\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都立于不败之地,有效2次"))) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, - message.Text(fmt.Sprintf("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次")))) + message.Text("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次"))) if id := ctx.Send(messages).ID(); id == 0 { ctx.Send(message.Text("发送商店失败")) } @@ -276,7 +300,7 @@ func init() { f float64 u userInfo ) - load, ok := prop.Load(fmt.Sprintf(t)) + load, ok := prop.Load(t) if ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8 { ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) messages, f = generateRandomStingTwo(niuniu.Length) @@ -376,18 +400,18 @@ func init() { myniuniu, err := db.findniuniu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!")) - jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) + jjLimiter.Delete(t) return } adduserniuniu, err := db.findniuniu(gid, adduser) if err != nil { ctx.SendChain(message.At(uid), message.Text("对方还没有牛牛呢,不能🤺")) - jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) + jjLimiter.Delete(t) return } if uid == adduser { ctx.SendChain(message.Text("你要和谁🤺?你自己吗?")) - jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) + jjLimiter.Delete(t) return } var ( @@ -399,7 +423,11 @@ func init() { v, ok := prop.Load(t) if ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8 { ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + _, f, _ = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } } else { switch { case myniuniu.Artifact > 0: @@ -420,52 +448,57 @@ func init() { updateMap(t, true) default: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + } - } - err = db.insertniuniu(&u, gid) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - err = db.insertniuniu(&userInfo{UID: adduser, Length: f1, UserCount: 0}, gid) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } - ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) - j := fmt.Sprintf("%d_%d", gid, adduser) - count, ok := jjCount.Load(j) - var c lastLength - if !ok { - c = lastLength{ - TimeLimit: time.Now(), - Count: 1, - Length: adduserniuniu.Length, + err = db.insertniuniu(&u, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return } - } else { - c = lastLength{ - TimeLimit: c.TimeLimit, - Count: count.Count + 1, - Length: count.Length, + err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return } - if time.Since(c.TimeLimit) > time.Minute*30 { + ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) + j := fmt.Sprintf("%d_%d", gid, adduser) + count, ok := jjCount.Load(j) + var c lastLength + if !ok { c = lastLength{ TimeLimit: time.Now(), Count: 1, Length: adduserniuniu.Length, } + } else { + c = lastLength{ + TimeLimit: c.TimeLimit, + Count: count.Count + 1, + Length: count.Length, + } + if time.Since(c.TimeLimit) > time.Minute*30 { + c = lastLength{ + TimeLimit: time.Now(), + Count: 1, + Length: adduserniuniu.Length, + } + } } - } - jjCount.Store(j, &c) - if c.Count > 5 { - ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), - "你们不要再找ta🤺啦!"}))) - if c.Count < 7 { - id := ctx.SendPrivateMessage(adduser, - message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) - if id == 0 { - ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) + jjCount.Store(j, &c) + if c.Count > 5 { + ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), + "你们不要再找ta🤺啦!"}))) + if c.Count < 7 { + id := ctx.SendPrivateMessage(adduser, + message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) + if id == 0 { + ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) + } } } } From acc2fc430cc8d0ab6cb6ea0c4aedd9d510bf628d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Fri, 13 Sep 2024 22:10:34 +0800 Subject: [PATCH 18/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 204 ++++++++++++++++++----------------------- plugin/niuniu/utils.go | 8 +- 2 files changed, 93 insertions(+), 119 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index c473d016f9..328d7aae77 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -36,7 +36,7 @@ var ( Help: "- 打胶\n" + "- jj@xxx\n" + "- 注册牛牛\n" + - "- 赎牛牛(cd:30分钟)\n" + + "- 赎牛牛(cd:45分钟)\n" + "- 牛牛商店\n" + "- 注销牛牛\n" + "- 查看我的牛牛\n" + @@ -50,30 +50,6 @@ var ( prop = syncx.Map[string, *propsCount]{} ) -/*func 渡劫成功与否(u userInfo, product bool) { - daojieSuccessRates := map[int]float64{ - 1: 0.8, //练气一层 - 2: 0.75, //练气二层 - 3: 0.7, //练气三层 - 4: 0.65, //练气四层 - 5: 0.6, //练气五层 - 6: 0.55, //练气六层 - 7: 0.5, //练气七层 - 8: 0.45, //练气八层 - 9: 0.4, //练气九层 - 10: 0.35, //金丹一层 - 11: 0.3, //金丹二层 - 12: 0.25, //金丹三层 - 13: 0.2, //金丹四层 - 14: 0.15, //金丹五层 - 15: 0.1, //金丹六层 - 16: 0.08, //金丹七层 - 17: 0.06, //金丹八层 - 18: 0.04, //金丹九层 - } - -}*/ - func init() { en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID @@ -99,6 +75,7 @@ func init() { recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`(/d+)`)).Repeat() defer cancel() timer := time.NewTimer(120 * time.Second) + defer timer.Stop() for { select { case <-timer.C: @@ -166,7 +143,7 @@ func init() { ctx.SendChain(message.Text("你还没有被厥呢")) return } - if time.Since(last.TimeLimit) > time.Minute*30 { + if time.Since(last.TimeLimit) > time.Minute*45 { ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!")) jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) return @@ -176,7 +153,7 @@ func init() { return } money := wallet.GetWalletOf(uid) - if money < 100 { + if money < 150 { ctx.SendChain(message.Text("赎牛牛需要150ATRI币,快去赚钱吧")) return } @@ -301,37 +278,35 @@ func init() { u userInfo ) load, ok := prop.Load(t) - if ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8 { + switch { + case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) messages, f = generateRandomStingTwo(niuniu.Length) u = userInfo{ UID: uid, Length: f, } - } else { - switch { - case niuniu.WeiGe > 0: - messages, f = useWeiGe(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - WeiGe: niuniu.WeiGe - 1, - } - updateMap(t, true) - case niuniu.Philter > 0: - messages, f = usePhilter(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Philter: niuniu.Philter - 1, - } - updateMap(t, true) - default: - messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } + case niuniu.WeiGe > 0: + messages, f = useWeiGe(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + WeiGe: niuniu.WeiGe - 1, + } + updateMap(t, true) + case niuniu.Philter > 0: + messages, f = usePhilter(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Philter: niuniu.Philter - 1, + } + updateMap(t, true) + default: + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, } } @@ -421,87 +396,86 @@ func init() { u userInfo ) v, ok := prop.Load(t) - if ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8 { + switch { + case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) - _, f, _ = fencing(myniuniu.Length, adduserniuniu.Length) + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) u = userInfo{ UID: uid, Length: f, } - } else { - switch { - case myniuniu.Artifact > 0: - fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.Artifact - 1, - } - updateMap(t, true) - case myniuniu.ShenJi > 0: - fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.ShenJi - 1, - } - updateMap(t, true) - default: - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - + case myniuniu.Artifact > 0: + fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Artifact: myniuniu.Artifact - 1, } - err = db.insertniuniu(&u, gid) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return + updateMap(t, true) + case myniuniu.ShenJi > 0: + fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Artifact: myniuniu.ShenJi - 1, } - err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return + updateMap(t, true) + default: + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + + } + err = db.insertniuniu(&u, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) + j := fmt.Sprintf("%d_%d", gid, adduser) + count, ok := jjCount.Load(j) + var c lastLength + if !ok { + c = lastLength{ + TimeLimit: time.Now(), + Count: 1, + Length: adduserniuniu.Length, } - ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) - j := fmt.Sprintf("%d_%d", gid, adduser) - count, ok := jjCount.Load(j) - var c lastLength - if !ok { + } else { + c = lastLength{ + TimeLimit: c.TimeLimit, + Count: count.Count + 1, + Length: count.Length, + } + if time.Since(c.TimeLimit) > time.Minute*45 { c = lastLength{ TimeLimit: time.Now(), Count: 1, Length: adduserniuniu.Length, } - } else { - c = lastLength{ - TimeLimit: c.TimeLimit, - Count: count.Count + 1, - Length: count.Length, - } - if time.Since(c.TimeLimit) > time.Minute*30 { - c = lastLength{ - TimeLimit: time.Now(), - Count: 1, - Length: adduserniuniu.Length, - } - } } + } - jjCount.Store(j, &c) - if c.Count > 5 { - ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), - "你们不要再找ta🤺啦!"}))) - if c.Count < 7 { - id := ctx.SendPrivateMessage(adduser, - message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) - if id == 0 { - ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) - } + jjCount.Store(j, &c) + if c.Count > 5 { + ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), + "你们不要再找ta🤺啦!"}))) + if c.Count < 7 { + id := ctx.SendPrivateMessage(adduser, + message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) + if id == 0 { + ctx.SendChain(message.At(adduser), message.Text("快发送`赎牛牛`来赎回你原本的牛牛!")) } } } + }) en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index d37d32bd4e..11ade66090 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -262,13 +262,13 @@ func hitGlue(l float64) float64 { l = math.Abs(l) switch { case l > 1 && l <= 10: - return rand.Float64() * math.Log2(l) + return rand.Float64() * math.Log2(l*2) case 10 < l && l <= 100: - return rand.Float64() * math.Log2(l*1.5) / 2 + return rand.Float64() * math.Log2(l*1.5) case 100 < l && l <= 1000: - return rand.Float64() * math.Log10(l*1.5) / 2 + return rand.Float64() * (math.Log10(l*1.5) * 2) case l > 1000: - return rand.Float64() * math.Log10(l) / 2 + return rand.Float64() * (math.Log10(l) * 2) default: return rand.Float64() } From a74efd727d085f544d90b68a96a8f97541f01d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Fri, 13 Sep 2024 22:33:06 +0800 Subject: [PATCH 19/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 104 ++------------------------------------ plugin/niuniu/utils.go | 111 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 99 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 328d7aae77..2a619a5189 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -93,28 +93,11 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - var ( - money int - u *userInfo - ) - switch n { - case 1: - money = 300 - u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} - case 2: - money = 300 - u = &userInfo{UID: uid, Philter: info.Philter + 5} - case 3: - money = 500 - u = &userInfo{UID: uid, Artifact: info.Artifact + 2} - case 4: - money = 500 - u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} - default: - ctx.SendChain(message.Text("无效的选项")) + u, money, err := purchaseItem(n, info, uid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) return } - if wallet.GetWalletOf(uid) < money { ctx.SendChain(message.Text("你还没有足够的ATRI币呢,不能购买")) return @@ -124,7 +107,6 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -272,44 +254,7 @@ func init() { dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - var ( - messages string - f float64 - u userInfo - ) - load, ok := prop.Load(t) - switch { - case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) - messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - case niuniu.WeiGe > 0: - messages, f = useWeiGe(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - WeiGe: niuniu.WeiGe - 1, - } - updateMap(t, true) - case niuniu.Philter > 0: - messages, f = usePhilter(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Philter: niuniu.Philter - 1, - } - updateMap(t, true) - default: - messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - } - + messages, u := processNiuniuAction(t, &niuniu, ctx, uid) ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -389,45 +334,7 @@ func init() { jjLimiter.Delete(t) return } - var ( - fencingResult string - f float64 - f1 float64 - u userInfo - ) - v, ok := prop.Load(t) - switch { - case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - case myniuniu.Artifact > 0: - fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.Artifact - 1, - } - updateMap(t, true) - case myniuniu.ShenJi > 0: - fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.ShenJi - 1, - } - updateMap(t, true) - default: - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - - } + fencingResult, f1, u := processJJuAction(&myniuniu, &adduserniuniu, t, ctx) err = db.insertniuniu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -499,7 +406,6 @@ func randomChoice(options []string) string { } func updateMap(t string, d bool) { - value, ok := prop.Load(t) if !d { if time.Since(value.TimeLimit) > time.Minute*8 { diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 11ade66090..d48a668808 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -2,11 +2,122 @@ package niuniu import ( + "errors" "fmt" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" "math" "math/rand" + "time" ) +func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, ctx *zero.Ctx) (string, float64, userInfo) { + var ( + fencingResult string + f float64 + f1 float64 + u userInfo + ) + v, ok := prop.Load(t) + switch { + case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + } + case myniuniu.Artifact > 0: + fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + Artifact: myniuniu.Artifact - 1, + } + updateMap(t, true) + case myniuniu.ShenJi > 0: + fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + Artifact: myniuniu.ShenJi - 1, + } + updateMap(t, true) + default: + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + } + } + return fencingResult, f1, u +} + +func processNiuniuAction(t string, niuniu *userInfo, ctx *zero.Ctx, uid int64) (string, userInfo) { + var ( + messages string + f float64 + u userInfo + ) + load, ok := prop.Load(t) + switch { + case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + case niuniu.WeiGe > 0: + messages, f = useWeiGe(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + WeiGe: niuniu.WeiGe - 1, + } + updateMap(t, true) + case niuniu.Philter > 0: + messages, f = usePhilter(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Philter: niuniu.Philter - 1, + } + updateMap(t, true) + default: + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + } + return messages, u +} + +func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { + var ( + money int + u *userInfo + ) + switch n { + case 1: + money = 300 + u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} + case 2: + money = 300 + u = &userInfo{UID: uid, Philter: info.Philter + 5} + case 3: + money = 500 + u = &userInfo{UID: uid, Artifact: info.Artifact + 2} + case 4: + money = 500 + u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} + default: + return nil, 0, errors.New("无效的选项") + } + return u, money, nil +} + func useWeiGe(niuniu float64) (string, float64) { reduce := math.Abs(hitGlue(niuniu)) niuniu += reduce From 75c77f1f32875483773afaca82f348ed352ce354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Fri, 13 Sep 2024 22:33:06 +0800 Subject: [PATCH 20/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 104 ++------------------------------------ plugin/niuniu/utils.go | 111 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 99 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 328d7aae77..2a619a5189 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -93,28 +93,11 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - var ( - money int - u *userInfo - ) - switch n { - case 1: - money = 300 - u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} - case 2: - money = 300 - u = &userInfo{UID: uid, Philter: info.Philter + 5} - case 3: - money = 500 - u = &userInfo{UID: uid, Artifact: info.Artifact + 2} - case 4: - money = 500 - u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} - default: - ctx.SendChain(message.Text("无效的选项")) + u, money, err := purchaseItem(n, info, uid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) return } - if wallet.GetWalletOf(uid) < money { ctx.SendChain(message.Text("你还没有足够的ATRI币呢,不能购买")) return @@ -124,7 +107,6 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -272,44 +254,7 @@ func init() { dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - var ( - messages string - f float64 - u userInfo - ) - load, ok := prop.Load(t) - switch { - case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) - messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - case niuniu.WeiGe > 0: - messages, f = useWeiGe(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - WeiGe: niuniu.WeiGe - 1, - } - updateMap(t, true) - case niuniu.Philter > 0: - messages, f = usePhilter(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Philter: niuniu.Philter - 1, - } - updateMap(t, true) - default: - messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - } - + messages, u := processNiuniuAction(t, &niuniu, ctx, uid) ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -389,45 +334,7 @@ func init() { jjLimiter.Delete(t) return } - var ( - fencingResult string - f float64 - f1 float64 - u userInfo - ) - v, ok := prop.Load(t) - switch { - case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - case myniuniu.Artifact > 0: - fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.Artifact - 1, - } - updateMap(t, true) - case myniuniu.ShenJi > 0: - fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - Artifact: myniuniu.ShenJi - 1, - } - updateMap(t, true) - default: - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: uid, - Length: f, - } - - } + fencingResult, f1, u := processJJuAction(&myniuniu, &adduserniuniu, t, ctx) err = db.insertniuniu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -499,7 +406,6 @@ func randomChoice(options []string) string { } func updateMap(t string, d bool) { - value, ok := prop.Load(t) if !d { if time.Since(value.TimeLimit) > time.Minute*8 { diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 11ade66090..d48a668808 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -2,11 +2,122 @@ package niuniu import ( + "errors" "fmt" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" "math" "math/rand" + "time" ) +func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, ctx *zero.Ctx) (string, float64, userInfo) { + var ( + fencingResult string + f float64 + f1 float64 + u userInfo + ) + v, ok := prop.Load(t) + switch { + case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + } + case myniuniu.Artifact > 0: + fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + Artifact: myniuniu.Artifact - 1, + } + updateMap(t, true) + case myniuniu.ShenJi > 0: + fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + Artifact: myniuniu.ShenJi - 1, + } + updateMap(t, true) + default: + fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) + u = userInfo{ + UID: myniuniu.UID, + Length: f, + } + } + return fencingResult, f1, u +} + +func processNiuniuAction(t string, niuniu *userInfo, ctx *zero.Ctx, uid int64) (string, userInfo) { + var ( + messages string + f float64 + u userInfo + ) + load, ok := prop.Load(t) + switch { + case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: + ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + case niuniu.WeiGe > 0: + messages, f = useWeiGe(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + WeiGe: niuniu.WeiGe - 1, + } + updateMap(t, true) + case niuniu.Philter > 0: + messages, f = usePhilter(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + Philter: niuniu.Philter - 1, + } + updateMap(t, true) + default: + messages, f = generateRandomStingTwo(niuniu.Length) + u = userInfo{ + UID: uid, + Length: f, + } + } + return messages, u +} + +func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { + var ( + money int + u *userInfo + ) + switch n { + case 1: + money = 300 + u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} + case 2: + money = 300 + u = &userInfo{UID: uid, Philter: info.Philter + 5} + case 3: + money = 500 + u = &userInfo{UID: uid, Artifact: info.Artifact + 2} + case 4: + money = 500 + u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} + default: + return nil, 0, errors.New("无效的选项") + } + return u, money, nil +} + func useWeiGe(niuniu float64) (string, float64) { reduce := math.Abs(hitGlue(niuniu)) niuniu += reduce From 09a24f71be1bd445a6855145f84a9f94f9d88af4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sat, 14 Sep 2024 22:19:18 +0800 Subject: [PATCH 21/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 10 ++++++++-- plugin/niuniu/utils.go | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 2a619a5189..bc02af71aa 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -254,7 +254,10 @@ func init() { dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - messages, u := processNiuniuAction(t, &niuniu, ctx, uid) + messages, u, err := processNiuniuAction(t, &niuniu) + if err != nil { + ctx.SendChain(message.Text(err)) + } ctx.SendChain(message.Text(messages)) if err = db.insertniuniu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -334,7 +337,10 @@ func init() { jjLimiter.Delete(t) return } - fencingResult, f1, u := processJJuAction(&myniuniu, &adduserniuniu, t, ctx) + fencingResult, f1, u, err := processJJuAction(&myniuniu, &adduserniuniu, t) + if err != nil { + ctx.SendChain(message.Text(err)) + } err = db.insertniuniu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index d48a668808..0821a749cf 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -4,29 +4,28 @@ package niuniu import ( "errors" "fmt" - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" "math" "math/rand" "time" ) -func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, ctx *zero.Ctx) (string, float64, userInfo) { +func processJJuAction(myniuniu, adduserniuniu *userInfo, t string) (string, float64, userInfo, error) { var ( fencingResult string f float64 f1 float64 u userInfo + err error ) v, ok := prop.Load(t) switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(v.TimeLimit), "再来吧")) fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) u = userInfo{ UID: myniuniu.UID, Length: f, } + err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) case myniuniu.Artifact > 0: fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) u = userInfo{ @@ -50,28 +49,29 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, ctx *zero.Ctx Length: f, } } - return fencingResult, f1, u + return fencingResult, f1, u, err } -func processNiuniuAction(t string, niuniu *userInfo, ctx *zero.Ctx, uid int64) (string, userInfo) { +func processNiuniuAction(t string, niuniu *userInfo) (string, userInfo, error) { var ( messages string f float64 u userInfo + err error ) load, ok := prop.Load(t) switch { case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: - ctx.SendChain(message.Text("你使用道具次数太快了,此次道具不会生效,等待", time.Minute*8-time.Since(load.TimeLimit), "再来吧")) messages, f = generateRandomStingTwo(niuniu.Length) u = userInfo{ - UID: uid, + UID: niuniu.UID, Length: f, } + err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))) case niuniu.WeiGe > 0: messages, f = useWeiGe(niuniu.Length) u = userInfo{ - UID: uid, + UID: niuniu.UID, Length: f, WeiGe: niuniu.WeiGe - 1, } @@ -79,7 +79,7 @@ func processNiuniuAction(t string, niuniu *userInfo, ctx *zero.Ctx, uid int64) ( case niuniu.Philter > 0: messages, f = usePhilter(niuniu.Length) u = userInfo{ - UID: uid, + UID: niuniu.UID, Length: f, Philter: niuniu.Philter - 1, } @@ -87,11 +87,11 @@ func processNiuniuAction(t string, niuniu *userInfo, ctx *zero.Ctx, uid int64) ( default: messages, f = generateRandomStingTwo(niuniu.Length) u = userInfo{ - UID: uid, + UID: niuniu.UID, Length: f, } } - return messages, u + return messages, u, err } func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { From da37ca690ea0315134312eb622d7044851c17dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sat, 14 Sep 2024 22:30:55 +0800 Subject: [PATCH 22/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 1 + plugin/niuniu/utils.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index bc02af71aa..6cdc4c6614 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -355,6 +355,7 @@ func init() { j := fmt.Sprintf("%d_%d", gid, adduser) count, ok := jjCount.Load(j) var c lastLength + // 按照第一次jj时的时间计算,超过45分钟则重置 if !ok { c = lastLength{ TimeLimit: time.Now(), diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 0821a749cf..3699258f7f 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -118,6 +118,7 @@ func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { return u, money, nil } +// useWeiGe 使用道具伟哥 func useWeiGe(niuniu float64) (string, float64) { reduce := math.Abs(hitGlue(niuniu)) niuniu += reduce @@ -128,6 +129,7 @@ func useWeiGe(niuniu float64) (string, float64) { }), niuniu } +// usePhilter 使用道具媚药 func usePhilter(niuniu float64) (string, float64) { reduce := math.Abs(hitGlue(niuniu)) niuniu -= reduce @@ -138,6 +140,7 @@ func usePhilter(niuniu float64) (string, float64) { }), niuniu } +// useArtifact 使用道具击剑神器 func useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { difference := myLength - adduserniuniu var ( @@ -158,6 +161,7 @@ func useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { }), myLength, adduserniuniu - change/1.3 } +// useShenJi 使用道具击剑神稽 func useShenJi(myLength, adduserniuniu float64) (string, float64, float64) { difference := myLength - adduserniuniu var ( From 40e77d85b78640a40f2cee1cecfae15a40f960fa 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, 15 Sep 2024 16:55:54 +0800 Subject: [PATCH 23/35] =?UTF-8?q?=E7=89=9B=E7=89=9B=E5=95=86=E5=BA=97?= =?UTF-8?q?=E6=94=B9=E9=9D=A2=E5=90=91=E5=AF=B9=E8=B1=A1=E5=BD=A2=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=8A=A0=E5=85=A5NiuNiuPlugin=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 32 ++++----- plugin/niuniu/model.go | 113 +++++++++++++++++++++++++---- plugin/niuniu/utils.go | 158 +++++++++++++---------------------------- 3 files changed, 164 insertions(+), 139 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 6cdc4c6614..0cbdab4900 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -88,7 +88,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - info, err := db.findniuniu(gid, uid) + info, err := db.FindNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -107,7 +107,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(u, gid) + err = db.InsertNiuNiu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -144,12 +144,12 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - u := &userInfo{ + u := &UserInfo{ UID: uid, Length: last.Length, UserCount: 0, } - err = db.insertniuniu(u, gid) + err = db.InsertNiuNiu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -206,7 +206,7 @@ func init() { en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID gid := ctx.Event.GroupID - i, err := db.findniuniu(gid, uid) + i, err := db.FindNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢不能查看!")) return @@ -248,7 +248,7 @@ func init() { uid := ctx.Event.UserID t := fmt.Sprintf("%d_%d", gid, uid) updateMap(t, false) - niuniu, err := db.findniuniu(gid, uid) + niuniu, err := db.FindNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("请先注册牛牛!")) dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) @@ -259,7 +259,7 @@ func init() { ctx.SendChain(message.Text(err)) } ctx.SendChain(message.Text(messages)) - if err = db.insertniuniu(&u, gid); err != nil { + if err = db.InsertNiuNiu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } @@ -267,26 +267,26 @@ func init() { en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID - if _, err := db.findniuniu(gid, uid); err == nil { + if _, err := db.FindNiuNiu(gid, uid); err == nil { ctx.SendChain(message.Text("你已经注册过了")) return } // 获取初始长度 long := db.randLength() - u := userInfo{ + u := UserInfo{ UID: uid, Length: long, UserCount: 0, } // 添加数据进入表 - err := db.insertniuniu(&u, gid) + err := db.InsertNiuNiu(&u, gid) if err != nil { err = db.createGIDTable(gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(&u, gid) + err = db.InsertNiuNiu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -320,13 +320,13 @@ func init() { gid := ctx.Event.GroupID t := fmt.Sprintf("%d_%d", gid, uid) updateMap(t, false) - myniuniu, err := db.findniuniu(gid, uid) + myniuniu, err := db.FindNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!")) jjLimiter.Delete(t) return } - adduserniuniu, err := db.findniuniu(gid, adduser) + adduserniuniu, err := db.FindNiuNiu(gid, adduser) if err != nil { ctx.SendChain(message.At(uid), message.Text("对方还没有牛牛呢,不能🤺")) jjLimiter.Delete(t) @@ -341,12 +341,12 @@ func init() { if err != nil { ctx.SendChain(message.Text(err)) } - err = db.insertniuniu(&u, gid) + err = db.InsertNiuNiu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid) + err = db.InsertNiuNiu(&UserInfo{UID: adduser, Length: f1}, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -394,7 +394,7 @@ func init() { en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID gid := ctx.Event.GroupID - _, err := db.findniuniu(gid, uid) + _, err := db.FindNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢,咋的你想凭空造一个啊")) return diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index a4374a3212..5941684f21 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -2,6 +2,8 @@ package niuniu import ( + "fmt" + "math" "math/rand" "sort" "strconv" @@ -19,17 +21,26 @@ type model struct { sync.RWMutex } -type userInfo struct { +type NiuPlugin interface { + FindNiuNiu(gid, uid int64) (UserInfo, error) + InsertNiuNiu(u *UserInfo, gid int64) error +} + +type UserInfo struct { UID int64 Length float64 UserCount int - WeiGe int // 伟哥 - Philter int // 媚药 - Artifact int // 击剑神器 - ShenJi int // 击剑神稽 + Prop *niuNiuProp +} + +type niuNiuProp struct { + WeiGe int // 伟哥 + Philter int // 媚药 + Artifact int // 击剑神器 + ShenJi int // 击剑神稽 } -type users []*userInfo +type users []*UserInfo var ( db = &model{} @@ -44,8 +55,82 @@ var ( }) ) +// useWeiGe 使用道具伟哥 +func (n *niuNiuProp) useWeiGe(niuniu float64) (string, float64) { + reduce := math.Abs(hitGlue(niuniu)) + niuniu += reduce + return randomChoice([]string{ + fmt.Sprintf("哈哈,你这一用道具,牛牛就像是被激发了潜能,增加了%.2fcm!看来今天是个大日子呢!", reduce), + fmt.Sprintf("你这是用了什么神奇的道具?牛牛竟然增加了%.2fcm,简直是牛气冲天!", reduce), + fmt.Sprintf("“使用道具后,你的牛牛就像是开启了加速模式,一下增加了%.2fcm,这成长速度让人惊叹!", reduce), + }), niuniu +} + +// usePhilter 使用道具媚药 +func (n *niuNiuProp) usePhilter(niuniu float64) (string, float64) { + reduce := math.Abs(hitGlue(niuniu)) + niuniu -= reduce + return randomChoice([]string{ + fmt.Sprintf("你使用媚药,咿呀咿呀一下使当前长度发生了一些变化,当前长度%.2f", niuniu), + fmt.Sprintf("看来你追求的是‘微观之美’,故意使用道具让牛牛凹进去了%.2fcm!", reduce), + fmt.Sprintf("‘缩小奇迹’在你身上发生了,牛牛凹进去了%.2fcm,你的选择真是独特!", reduce), + }), niuniu +} + +// useArtifact 使用道具击剑神器 +func (n *niuNiuProp) useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { + difference := myLength - adduserniuniu + var ( + change float64 + ) + if difference > 0 { + change = hitGlue(myLength + adduserniuniu) + } else { + change = hitGlue((myLength + adduserniuniu) / 2) + } + myLength += change + return randomChoice([]string{ + fmt.Sprintf("凭借神秘道具的力量,你让对方在你的长度面前俯首称臣!你的长度增加了%.2fcm,当前长度达到了%.2fcm", change, myLength), + fmt.Sprintf("神器在手,天下我有!你使用道具后,长度猛增%.2fcm,现在的总长度是%.2fcm,无人能敌!", change, myLength), + fmt.Sprintf("这就是道具的魔力!你轻松增加了%.2fcm,让对手望尘莫及,当前长度为%.2fcm!", change, myLength), + fmt.Sprintf("道具一出,谁与争锋!你的长度因道具而增长%.2fcm,现在的长度是%.2fcm,霸气尽显!", change, myLength), + fmt.Sprintf("使用道具的你,如同获得神助!你的长度增长了%.2fcm,达到%.2fcm的惊人长度,胜利自然到手!", change, myLength), + }), myLength, adduserniuniu - change/1.3 +} + +// useShenJi 使用道具击剑神稽 +func (n *niuNiuProp) useShenJi(myLength, adduserniuniu float64) (string, float64, float64) { + difference := myLength - adduserniuniu + var ( + change float64 + ) + if difference > 0 { + change = hitGlue(myLength + adduserniuniu) + } else { + change = hitGlue((myLength + adduserniuniu) / 2) + } + myLength -= change + var r string + if myLength > 0 { + r = randomChoice([]string{ + fmt.Sprintf("哦吼!?看来你的牛牛因为使用了神秘道具而缩水了呢🤣🤣🤣!缩小了%.2fcm!", change), + fmt.Sprintf("哈哈,看来这个道具有点儿调皮,让你的长度缩水了%.2fcm!现在你的长度是%.2fcm,下次可得小心使用哦!", change, myLength), + fmt.Sprintf("使用道具后,你的牛牛似乎有点儿害羞,缩水了%.2fcm!现在的长度是%.2fcm,希望下次它能挺直腰板!", change, myLength), + fmt.Sprintf("哎呀,这个道具的效果有点儿意外,你的长度减少了%.2fcm,现在只有%.2fcm了!下次选道具可得睁大眼睛!", change, myLength), + }) + } else { + r = randomChoice([]string{ + fmt.Sprintf("哦哟,小姐姐真是玩得一手好游戏,使用道具后数值又降低了%.2fcm,小巧得更显魅力!", change), + fmt.Sprintf("看来小姐姐喜欢更加精致的风格,使用道具后,数值减少了%.2fcm,更加迷人了!", change), + fmt.Sprintf("小姐姐的每一次变化都让人惊喜,使用道具后,数值减少了%.2fcm,更加优雅动人!", change), + fmt.Sprintf("小姐姐这是在展示什么是真正的精致小巧,使用道具后,数值减少了%.2fcm,美得不可方物!", change), + }) + } + return r, myLength, adduserniuniu + 0.7*change +} + func (m users) positive() users { - var m1 []*userInfo + var m1 []*UserInfo for _, i2 := range m { if i2.Length > 0 { m1 = append(m1, i2) @@ -55,7 +140,7 @@ func (m users) positive() users { } func (m users) negative() users { - var m1 []*userInfo + var m1 []*UserInfo for _, i2 := range m { if i2.Length <= 0 { m1 = append(m1, i2) @@ -94,18 +179,20 @@ func (db *model) randLength() float64 { func (db *model) createGIDTable(gid int64) error { db.Lock() defer db.Unlock() - return db.sql.Create(strconv.FormatInt(gid, 10), &userInfo{}) + return db.sql.Create(strconv.FormatInt(gid, 10), &UserInfo{}) } -func (db *model) findniuniu(gid, uid int64) (userInfo, error) { +// FindNiuNiu 返回一个用户的牛牛信息 +func (db *model) FindNiuNiu(gid, uid int64) (UserInfo, error) { db.RLock() defer db.RUnlock() - u := userInfo{} + u := UserInfo{} err := db.sql.Find(strconv.FormatInt(gid, 10), &u, "where UID = "+strconv.FormatInt(uid, 10)) return u, err } -func (db *model) insertniuniu(u *userInfo, gid int64) error { +// InsertNiuNiu 更新一个用户的牛牛信息 +func (db *model) InsertNiuNiu(u *UserInfo, gid int64) error { db.Lock() defer db.Unlock() return db.sql.Insert(strconv.FormatInt(gid, 10), u) @@ -120,6 +207,6 @@ func (db *model) deleteniuniu(gid, uid int64) error { func (db *model) readAllTable(gid int64) (users, error) { db.Lock() defer db.Unlock() - a, err := sql.FindAll[userInfo](&db.sql, strconv.FormatInt(gid, 10), "where UserCount = 0") + a, err := sql.FindAll[UserInfo](&db.sql, strconv.FormatInt(gid, 10), "where UserCount = 0") return a, err } diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 3699258f7f..47618464f0 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -9,42 +9,42 @@ import ( "time" ) -func processJJuAction(myniuniu, adduserniuniu *userInfo, t string) (string, float64, userInfo, error) { +func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, float64, UserInfo, error) { var ( fencingResult string f float64 f1 float64 - u userInfo + u UserInfo err error ) v, ok := prop.Load(t) switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ + u = UserInfo{ UID: myniuniu.UID, Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) - case myniuniu.Artifact > 0: - fencingResult, f, f1 = useArtifact(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - Artifact: myniuniu.Artifact - 1, + case myniuniu.Prop.Artifact > 0: + fencingResult, f, f1 = myniuniu.Prop.useArtifact(myniuniu.Length, adduserniuniu.Length) + u = UserInfo{ + UID: myniuniu.UID, + Length: f, + Prop: &niuNiuProp{Artifact: myniuniu.Prop.Artifact - 1}, } updateMap(t, true) - case myniuniu.ShenJi > 0: - fencingResult, f, f1 = useShenJi(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - Artifact: myniuniu.ShenJi - 1, + case myniuniu.Prop.ShenJi > 0: + fencingResult, f, f1 = myniuniu.Prop.useShenJi(myniuniu.Length, adduserniuniu.Length) + u = UserInfo{ + UID: myniuniu.UID, + Length: f, + Prop: &niuNiuProp{ShenJi: myniuniu.Prop.ShenJi - 1}, } updateMap(t, true) default: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ + u = UserInfo{ UID: myniuniu.UID, Length: f, } @@ -52,41 +52,41 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string) (string, floa return fencingResult, f1, u, err } -func processNiuniuAction(t string, niuniu *userInfo) (string, userInfo, error) { +func processNiuniuAction(t string, niuniu *UserInfo) (string, UserInfo, error) { var ( messages string f float64 - u userInfo + u UserInfo err error ) load, ok := prop.Load(t) switch { case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ + u = UserInfo{ UID: niuniu.UID, Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))) - case niuniu.WeiGe > 0: - messages, f = useWeiGe(niuniu.Length) - u = userInfo{ + case niuniu.Prop.WeiGe > 0: + messages, f = niuniu.Prop.useWeiGe(niuniu.Length) + u = UserInfo{ UID: niuniu.UID, Length: f, - WeiGe: niuniu.WeiGe - 1, + Prop: &niuNiuProp{WeiGe: niuniu.Prop.WeiGe - 1}, } updateMap(t, true) - case niuniu.Philter > 0: - messages, f = usePhilter(niuniu.Length) - u = userInfo{ - UID: niuniu.UID, - Length: f, - Philter: niuniu.Philter - 1, + case niuniu.Prop.Philter > 0: + messages, f = niuniu.Prop.usePhilter(niuniu.Length) + u = UserInfo{ + UID: niuniu.UID, + Length: f, + Prop: &niuNiuProp{Philter: niuniu.Prop.Philter - 1}, } updateMap(t, true) default: messages, f = generateRandomStingTwo(niuniu.Length) - u = userInfo{ + u = UserInfo{ UID: niuniu.UID, Length: f, } @@ -94,104 +94,42 @@ func processNiuniuAction(t string, niuniu *userInfo) (string, userInfo, error) { return messages, u, err } -func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { +func purchaseItem(n int, info UserInfo, uid int64) (*UserInfo, int, error) { var ( money int - u *userInfo + u *UserInfo ) switch n { case 1: money = 300 - u = &userInfo{UID: uid, WeiGe: info.WeiGe + 5} + u = &UserInfo{ + UID: uid, + Prop: &niuNiuProp{WeiGe: info.Prop.WeiGe + 5}, + } case 2: money = 300 - u = &userInfo{UID: uid, Philter: info.Philter + 5} + u = &UserInfo{ + UID: uid, + Prop: &niuNiuProp{Philter: info.Prop.Philter + 5}, + } case 3: money = 500 - u = &userInfo{UID: uid, Artifact: info.Artifact + 2} + u = &UserInfo{ + UID: uid, + Prop: &niuNiuProp{Artifact: info.Prop.Artifact + 2}, + } case 4: money = 500 - u = &userInfo{UID: uid, ShenJi: info.ShenJi + 2} + u = &UserInfo{ + UID: uid, + Prop: &niuNiuProp{ShenJi: info.Prop.ShenJi + 2}, + } default: return nil, 0, errors.New("无效的选项") } return u, money, nil } -// useWeiGe 使用道具伟哥 -func useWeiGe(niuniu float64) (string, float64) { - reduce := math.Abs(hitGlue(niuniu)) - niuniu += reduce - return randomChoice([]string{ - fmt.Sprintf("哈哈,你这一用道具,牛牛就像是被激发了潜能,增加了%.2fcm!看来今天是个大日子呢!", reduce), - fmt.Sprintf("你这是用了什么神奇的道具?牛牛竟然增加了%.2fcm,简直是牛气冲天!", reduce), - fmt.Sprintf("“使用道具后,你的牛牛就像是开启了加速模式,一下增加了%.2fcm,这成长速度让人惊叹!", reduce), - }), niuniu -} - -// usePhilter 使用道具媚药 -func usePhilter(niuniu float64) (string, float64) { - reduce := math.Abs(hitGlue(niuniu)) - niuniu -= reduce - return randomChoice([]string{ - fmt.Sprintf("你使用媚药,咿呀咿呀一下使当前长度发生了一些变化,当前长度%.2f", niuniu), - fmt.Sprintf("看来你追求的是‘微观之美’,故意使用道具让牛牛凹进去了%.2fcm!", reduce), - fmt.Sprintf("‘缩小奇迹’在你身上发生了,牛牛凹进去了%.2fcm,你的选择真是独特!", reduce), - }), niuniu -} - -// useArtifact 使用道具击剑神器 -func useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { - difference := myLength - adduserniuniu - var ( - change float64 - ) - if difference > 0 { - change = hitGlue(myLength + adduserniuniu) - } else { - change = hitGlue((myLength + adduserniuniu) / 2) - } - myLength += change - return randomChoice([]string{ - fmt.Sprintf("凭借神秘道具的力量,你让对方在你的长度面前俯首称臣!你的长度增加了%.2fcm,当前长度达到了%.2fcm", change, myLength), - fmt.Sprintf("神器在手,天下我有!你使用道具后,长度猛增%.2fcm,现在的总长度是%.2fcm,无人能敌!", change, myLength), - fmt.Sprintf("这就是道具的魔力!你轻松增加了%.2fcm,让对手望尘莫及,当前长度为%.2fcm!", change, myLength), - fmt.Sprintf("道具一出,谁与争锋!你的长度因道具而增长%.2fcm,现在的长度是%.2fcm,霸气尽显!", change, myLength), - fmt.Sprintf("使用道具的你,如同获得神助!你的长度增长了%.2fcm,达到%.2fcm的惊人长度,胜利自然到手!", change, myLength), - }), myLength, adduserniuniu - change/1.3 -} - -// useShenJi 使用道具击剑神稽 -func useShenJi(myLength, adduserniuniu float64) (string, float64, float64) { - difference := myLength - adduserniuniu - var ( - change float64 - ) - if difference > 0 { - change = hitGlue(myLength + adduserniuniu) - } else { - change = hitGlue((myLength + adduserniuniu) / 2) - } - myLength -= change - var r string - if myLength > 0 { - r = randomChoice([]string{ - fmt.Sprintf("哦吼!?看来你的牛牛因为使用了神秘道具而缩水了呢🤣🤣🤣!缩小了%.2fcm!", change), - fmt.Sprintf("哈哈,看来这个道具有点儿调皮,让你的长度缩水了%.2fcm!现在你的长度是%.2fcm,下次可得小心使用哦!", change, myLength), - fmt.Sprintf("使用道具后,你的牛牛似乎有点儿害羞,缩水了%.2fcm!现在的长度是%.2fcm,希望下次它能挺直腰板!", change, myLength), - fmt.Sprintf("哎呀,这个道具的效果有点儿意外,你的长度减少了%.2fcm,现在只有%.2fcm了!下次选道具可得睁大眼睛!", change, myLength), - }) - } else { - r = randomChoice([]string{ - fmt.Sprintf("哦哟,小姐姐真是玩得一手好游戏,使用道具后数值又降低了%.2fcm,小巧得更显魅力!", change), - fmt.Sprintf("看来小姐姐喜欢更加精致的风格,使用道具后,数值减少了%.2fcm,更加迷人了!", change), - fmt.Sprintf("小姐姐的每一次变化都让人惊喜,使用道具后,数值减少了%.2fcm,更加优雅动人!", change), - fmt.Sprintf("小姐姐这是在展示什么是真正的精致小巧,使用道具后,数值减少了%.2fcm,美得不可方物!", change), - }) - } - return r, myLength, adduserniuniu + 0.7*change -} - func generateRandomStingTwo(niuniu float64) (string, float64) { probability := rand.Intn(100 + 1) reduce := math.Abs(hitGlue(niuniu)) From 704f2e88d30056480dee9309e71574f2e8b648bf 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, 15 Sep 2024 22:59:41 +0800 Subject: [PATCH 24/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 18 ++++++++++++++ plugin/niuniu/model.go | 24 +++++++++---------- plugin/niuniu/utils.go | 53 +++++++++++++++++++++--------------------- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 0cbdab4900..f475671f67 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -38,6 +38,7 @@ var ( "- 注册牛牛\n" + "- 赎牛牛(cd:45分钟)\n" + "- 牛牛商店\n" + + "- 牛牛背包\n" + "- 注销牛牛\n" + "- 查看我的牛牛\n" + "- 牛子长度排行\n" + @@ -51,6 +52,20 @@ var ( ) func init() { + en.OnFullMatch("牛牛背包", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { + gid := ctx.Event.GroupID + uid := ctx.Event.UserID + niu, err := db.FindNiuNiu(gid, uid) + if err != nil { + ctx.SendChain(message.Text("你还没有牛牛呢快去注册一个吧!")) + return + } + ctx.SendChain(message.Text(fmt.Sprintln("当前牛牛背包如下"), + fmt.Sprintf("伟哥:%d\n", niu.WeiGe), + fmt.Sprintf("媚药:%d\n", niu.Philter), + fmt.Sprintf("击剑神器:%d\n", niu.Artifact), + fmt.Sprintf("击剑神稽:%d\n", niu.ShenJi))) + }) en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.GroupID @@ -414,6 +429,9 @@ func randomChoice(options []string) string { func updateMap(t string, d bool) { value, ok := prop.Load(t) + if value == nil { + return + } if !d { if time.Since(value.TimeLimit) > time.Minute*8 { prop.Delete(t) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 5941684f21..b28d43ec85 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -30,14 +30,10 @@ type UserInfo struct { UID int64 Length float64 UserCount int - Prop *niuNiuProp -} - -type niuNiuProp struct { - WeiGe int // 伟哥 - Philter int // 媚药 - Artifact int // 击剑神器 - ShenJi int // 击剑神稽 + WeiGe int // 伟哥 + Philter int // 媚药 + Artifact int // 击剑神器 + ShenJi int // 击剑神稽 } type users []*UserInfo @@ -56,7 +52,8 @@ var ( ) // useWeiGe 使用道具伟哥 -func (n *niuNiuProp) useWeiGe(niuniu float64) (string, float64) { +func (u *UserInfo) useWeiGe() (string, float64) { + niuniu := u.Length reduce := math.Abs(hitGlue(niuniu)) niuniu += reduce return randomChoice([]string{ @@ -67,7 +64,8 @@ func (n *niuNiuProp) useWeiGe(niuniu float64) (string, float64) { } // usePhilter 使用道具媚药 -func (n *niuNiuProp) usePhilter(niuniu float64) (string, float64) { +func (u *UserInfo) usePhilter() (string, float64) { + niuniu := u.Length reduce := math.Abs(hitGlue(niuniu)) niuniu -= reduce return randomChoice([]string{ @@ -78,7 +76,8 @@ func (n *niuNiuProp) usePhilter(niuniu float64) (string, float64) { } // useArtifact 使用道具击剑神器 -func (n *niuNiuProp) useArtifact(myLength, adduserniuniu float64) (string, float64, float64) { +func (u *UserInfo) useArtifact(adduserniuniu float64) (string, float64, float64) { + myLength := u.Length difference := myLength - adduserniuniu var ( change float64 @@ -99,7 +98,8 @@ func (n *niuNiuProp) useArtifact(myLength, adduserniuniu float64) (string, float } // useShenJi 使用道具击剑神稽 -func (n *niuNiuProp) useShenJi(myLength, adduserniuniu float64) (string, float64, float64) { +func (u *UserInfo) useShenJi(adduserniuniu float64) (string, float64, float64) { + myLength := u.Length difference := myLength - adduserniuniu var ( change float64 diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 47618464f0..69ed72181f 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -26,20 +26,21 @@ func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, floa Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) - case myniuniu.Prop.Artifact > 0: - fencingResult, f, f1 = myniuniu.Prop.useArtifact(myniuniu.Length, adduserniuniu.Length) + case myniuniu.Artifact > 0: + fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) u = UserInfo{ - UID: myniuniu.UID, - Length: f, - Prop: &niuNiuProp{Artifact: myniuniu.Prop.Artifact - 1}, + UID: myniuniu.UID, + Length: f, + Artifact: myniuniu.Artifact - 1, } updateMap(t, true) - case myniuniu.Prop.ShenJi > 0: - fencingResult, f, f1 = myniuniu.Prop.useShenJi(myniuniu.Length, adduserniuniu.Length) + case myniuniu.ShenJi > 0: + fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) u = UserInfo{ - UID: myniuniu.UID, - Length: f, - Prop: &niuNiuProp{ShenJi: myniuniu.Prop.ShenJi - 1}, + UID: 0, + Length: 0, + UserCount: 0, + ShenJi: myniuniu.ShenJi - 1, } updateMap(t, true) default: @@ -68,20 +69,20 @@ func processNiuniuAction(t string, niuniu *UserInfo) (string, UserInfo, error) { Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))) - case niuniu.Prop.WeiGe > 0: - messages, f = niuniu.Prop.useWeiGe(niuniu.Length) + case niuniu.WeiGe > 0: + messages, f = niuniu.useWeiGe() u = UserInfo{ UID: niuniu.UID, Length: f, - Prop: &niuNiuProp{WeiGe: niuniu.Prop.WeiGe - 1}, + WeiGe: niuniu.WeiGe - 1, } updateMap(t, true) - case niuniu.Prop.Philter > 0: - messages, f = niuniu.Prop.usePhilter(niuniu.Length) + case niuniu.Philter > 0: + messages, f = niuniu.usePhilter() u = UserInfo{ - UID: niuniu.UID, - Length: f, - Prop: &niuNiuProp{Philter: niuniu.Prop.Philter - 1}, + UID: niuniu.UID, + Length: f, + Philter: niuniu.Philter - 1, } updateMap(t, true) default: @@ -103,26 +104,26 @@ func purchaseItem(n int, info UserInfo, uid int64) (*UserInfo, int, error) { case 1: money = 300 u = &UserInfo{ - UID: uid, - Prop: &niuNiuProp{WeiGe: info.Prop.WeiGe + 5}, + UID: uid, + WeiGe: info.WeiGe + 5, } case 2: money = 300 u = &UserInfo{ - UID: uid, - Prop: &niuNiuProp{Philter: info.Prop.Philter + 5}, + UID: uid, + Philter: info.Philter + 5, } case 3: money = 500 u = &UserInfo{ - UID: uid, - Prop: &niuNiuProp{Artifact: info.Prop.Artifact + 2}, + UID: uid, + Artifact: info.Artifact + 2, } case 4: money = 500 u = &UserInfo{ - UID: uid, - Prop: &niuNiuProp{ShenJi: info.Prop.ShenJi + 2}, + UID: uid, + ShenJi: info.ShenJi + 2, } default: return nil, 0, errors.New("无效的选项") From ffcede5ebf1c1b9b705fa99978da651b82520255 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Tue, 17 Sep 2024 23:23:02 +0800 Subject: [PATCH 25/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=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 | 31 ++++++----- plugin/niuniu/model.go | 5 -- plugin/niuniu/utils.go | 122 +++++++++++++++++++++++++++++------------ 3 files changed, 106 insertions(+), 52 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index f475671f67..c2d7c7225b 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -60,17 +60,17 @@ func init() { ctx.SendChain(message.Text("你还没有牛牛呢快去注册一个吧!")) return } - ctx.SendChain(message.Text(fmt.Sprintln("当前牛牛背包如下"), - fmt.Sprintf("伟哥:%d\n", niu.WeiGe), - fmt.Sprintf("媚药:%d\n", niu.Philter), - fmt.Sprintf("击剑神器:%d\n", niu.Artifact), - fmt.Sprintf("击剑神稽:%d\n", niu.ShenJi))) + ctx.SendChain(message.Text("当前牛牛背包如下\n", + "伟哥:", niu.WeiGe, + "\n媚药:", niu.Philter, + "\n击剑神器:", niu.Artifact, + "\n击剑神稽:", niu.ShenJi)) }) en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.GroupID var messages message.Message - messages = append(messages, message.Text("牛牛商店当前售卖的物品如下")) + messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下"))) messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("商品1\n商品名:伟哥\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都增长,有效5次"))) @@ -85,11 +85,13 @@ func init() { message.Text("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次"))) 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+)$`)).Repeat() defer cancel() timer := time.NewTimer(120 * time.Second) + answer := "" defer timer.Stop() for { select { @@ -97,7 +99,7 @@ func init() { ctx.SendChain(message.At(uid), message.Text("超时,已自动取消")) return case r := <-recv: - answer := r.Event.Message.String() + answer = r.Event.Message.String() n, err := strconv.Atoi(answer) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -244,7 +246,7 @@ func init() { sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu))) ctx.SendChain(message.At(uid), message.Text(&result)) }) - en.OnFullMatchGroup([]string{"dj", "打胶"}, zero.OnlyGroup, + en.OnRegex(`^(?:.*使用(.*))??打胶$`, zero.OnlyGroup, getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter { lt := dajiaoLimiter.Load(fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)) ctx.State["dajiao_last_touch"] = lt.LastTouch() @@ -262,6 +264,7 @@ func init() { gid := ctx.Event.GroupID uid := ctx.Event.UserID t := fmt.Sprintf("%d_%d", gid, uid) + fiancee := ctx.State["regex_matched"].([]string) updateMap(t, false) niuniu, err := db.FindNiuNiu(gid, uid) if err != nil { @@ -269,9 +272,10 @@ func init() { dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - messages, u, err := processNiuniuAction(t, &niuniu) + messages, u, err := processNiuniuAction(t, &niuniu, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) + return } ctx.SendChain(message.Text(messages)) if err = db.InsertNiuNiu(&u, gid); err != nil { @@ -310,7 +314,7 @@ func init() { ctx.SendChain(message.Reply(ctx.Event.GroupID), message.Text("注册成功,你的牛牛现在有", u.Length, "cm")) }) - en.OnRegex(`^jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb, + en.OnRegex(`^(?:.*使用(.*))??jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb, zero.OnlyGroup).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter { lt := jjLimiter.Load(fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID)) ctx.State["jj_last_touch"] = lt.LastTouch() @@ -326,7 +330,7 @@ func init() { }, ).Handle(func(ctx *zero.Ctx) { fiancee := ctx.State["regex_matched"].([]string) - adduser, err := strconv.ParseInt(fiancee[2]+fiancee[3], 10, 64) + adduser, err := strconv.ParseInt(fiancee[3]+fiancee[4], 10, 64) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -352,9 +356,10 @@ func init() { jjLimiter.Delete(t) return } - fencingResult, f1, u, err := processJJuAction(&myniuniu, &adduserniuniu, t) + fencingResult, f1, u, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) + return } err = db.InsertNiuNiu(&u, gid) if err != nil { diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index b28d43ec85..aa1a84bded 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -21,11 +21,6 @@ type model struct { sync.RWMutex } -type NiuPlugin interface { - FindNiuNiu(gid, uid int64) (UserInfo, error) - InsertNiuNiu(u *UserInfo, gid int64) error -} - type UserInfo struct { UID int64 Length float64 diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 69ed72181f..77d5bafce4 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -9,7 +9,59 @@ import ( "time" ) -func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, float64, UserInfo, error) { +func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { + var ( + u UserInfo + err error + ) + switch props { + case "伟哥": + if niuniu.WeiGe > 0 { + u = UserInfo{ + UID: niuniu.UID, + Length: niuniu.Length, + WeiGe: niuniu.WeiGe - 1, + } + } else { + err = errors.New("你还没有伟哥呢,不能使用") + } + case "媚药": + if niuniu.Philter > 0 { + u = UserInfo{ + UID: niuniu.UID, + Length: niuniu.Length, + Philter: niuniu.Philter - 1, + } + } else { + err = errors.New("你还没有媚药呢,不能使用") + } + case "击剑神器": + if niuniu.Artifact > 0 { + u = UserInfo{ + UID: niuniu.UID, + Length: niuniu.Length, + Artifact: niuniu.Artifact - 1, + } + } else { + err = errors.New("你还没有击剑神器呢,不能使用") + } + case "击剑神稽": + if niuniu.ShenJi > 0 { + u = UserInfo{ + UID: niuniu.UID, + Length: niuniu.Length, + ShenJi: niuniu.ShenJi - 1, + } + } else { + err = errors.New("你还没有击剑神稽呢,不能使用") + } + default: + err = errors.New("道具不存在") + } + return u, err +} + +func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string, props string) (string, float64, UserInfo, error) { var ( fencingResult string f float64 @@ -18,6 +70,15 @@ func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, floa err error ) v, ok := prop.Load(t) + if props != "" { + if props != "击剑神器" && props != "击剑神稽" { + return "", 0, UserInfo{}, errors.New("道具不存在") + } + u, err = createUserInfoByProps(props, myniuniu) + if err != nil { + return "", 0, UserInfo{}, err + } + } switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) @@ -26,21 +87,18 @@ func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, floa Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) - case myniuniu.Artifact > 0: - fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) + case myniuniu.ShenJi-u.ShenJi != 0: + fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) u = UserInfo{ - UID: myniuniu.UID, - Length: f, - Artifact: myniuniu.Artifact - 1, + UID: myniuniu.UID, + Length: f, } updateMap(t, true) - case myniuniu.ShenJi > 0: - fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) + case myniuniu.Artifact-u.Artifact != 0: + fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) u = UserInfo{ - UID: 0, - Length: 0, - UserCount: 0, - ShenJi: myniuniu.ShenJi - 1, + UID: myniuniu.UID, + Length: f, } updateMap(t, true) default: @@ -52,8 +110,7 @@ func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string) (string, floa } return fencingResult, f1, u, err } - -func processNiuniuAction(t string, niuniu *UserInfo) (string, UserInfo, error) { +func processNiuniuAction(t string, niuniu *UserInfo, props string) (string, UserInfo, error) { var ( messages string f float64 @@ -61,36 +118,33 @@ func processNiuniuAction(t string, niuniu *UserInfo) (string, UserInfo, error) { err error ) load, ok := prop.Load(t) + if props != "" { + if props != "伟哥" && props != "媚药" { + return "", u, errors.New("道具不存在") + } + u, err = createUserInfoByProps(props, niuniu) + if err != nil { + return "", UserInfo{}, err + } + } switch { case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: messages, f = generateRandomStingTwo(niuniu.Length) - u = UserInfo{ - UID: niuniu.UID, - Length: f, - } + u.Length = f + u.UID = niuniu.UID err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))) - case niuniu.WeiGe > 0: + case niuniu.WeiGe-u.WeiGe != 0: messages, f = niuniu.useWeiGe() - u = UserInfo{ - UID: niuniu.UID, - Length: f, - WeiGe: niuniu.WeiGe - 1, - } + u.Length = f updateMap(t, true) - case niuniu.Philter > 0: + case niuniu.Philter-u.Philter != 0: messages, f = niuniu.usePhilter() - u = UserInfo{ - UID: niuniu.UID, - Length: f, - Philter: niuniu.Philter - 1, - } + u.Length = f updateMap(t, true) default: messages, f = generateRandomStingTwo(niuniu.Length) - u = UserInfo{ - UID: niuniu.UID, - Length: f, - } + u.Length = f + u.UID = niuniu.UID } return messages, u, err } From 0c817c9420cd5825e78dc9a94e717a439f6136e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sat, 21 Sep 2024 14:42:22 +0800 Subject: [PATCH 26/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++ plugin/niuniu/main.go | 37 +++++++++++++------------ plugin/niuniu/model.go | 30 ++++++++++---------- plugin/niuniu/utils.go | 62 +++++++++++++++++++++--------------------- 4 files changed, 70 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index e5de87d8ab..83410c552b 100644 --- a/README.md +++ b/README.md @@ -1035,8 +1035,12 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 打胶 +- [x] 使用[道具名称]打胶 + - [x] jj[@xxx] +- [x] 使用[道具名称]jj[@xxx] + - [x] 赎牛牛 - [x] 牛牛商店 diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index c2d7c7225b..2c40fd2a50 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -34,7 +34,9 @@ var ( DisableOnDefault: false, Brief: "牛牛大作战", Help: "- 打胶\n" + + "使用[道具名称]打胶\n" + "- jj@xxx\n" + + "使用[道具名称]jj@xxx\n" + "- 注册牛牛\n" + "- 赎牛牛(cd:45分钟)\n" + "- 牛牛商店\n" + @@ -55,7 +57,7 @@ func init() { en.OnFullMatch("牛牛背包", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID - niu, err := db.FindNiuNiu(gid, uid) + niu, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢快去注册一个吧!")) return @@ -105,7 +107,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - info, err := db.FindNiuNiu(gid, uid) + info, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -124,7 +126,7 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.InsertNiuNiu(u, gid) + err = db.insertNiuNiu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -161,12 +163,12 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - u := &UserInfo{ + u := &userInfo{ UID: uid, Length: last.Length, UserCount: 0, } - err = db.InsertNiuNiu(u, gid) + err = db.insertNiuNiu(u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -223,7 +225,7 @@ func init() { en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID gid := ctx.Event.GroupID - i, err := db.FindNiuNiu(gid, uid) + i, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢不能查看!")) return @@ -266,7 +268,7 @@ func init() { t := fmt.Sprintf("%d_%d", gid, uid) fiancee := ctx.State["regex_matched"].([]string) updateMap(t, false) - niuniu, err := db.FindNiuNiu(gid, uid) + niuniu, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("请先注册牛牛!")) dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) @@ -278,7 +280,7 @@ func init() { return } ctx.SendChain(message.Text(messages)) - if err = db.InsertNiuNiu(&u, gid); err != nil { + if err = db.insertNiuNiu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } @@ -286,26 +288,26 @@ func init() { en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID uid := ctx.Event.UserID - if _, err := db.FindNiuNiu(gid, uid); err == nil { + if _, err := db.findNiuNiu(gid, uid); err == nil { ctx.SendChain(message.Text("你已经注册过了")) return } // 获取初始长度 long := db.randLength() - u := UserInfo{ + u := userInfo{ UID: uid, Length: long, UserCount: 0, } // 添加数据进入表 - err := db.InsertNiuNiu(&u, gid) + err := db.insertNiuNiu(&u, gid) if err != nil { err = db.createGIDTable(gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.InsertNiuNiu(&u, gid) + err = db.insertNiuNiu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -339,13 +341,13 @@ func init() { gid := ctx.Event.GroupID t := fmt.Sprintf("%d_%d", gid, uid) updateMap(t, false) - myniuniu, err := db.FindNiuNiu(gid, uid) + myniuniu, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!")) jjLimiter.Delete(t) return } - adduserniuniu, err := db.FindNiuNiu(gid, adduser) + adduserniuniu, err := db.findNiuNiu(gid, adduser) if err != nil { ctx.SendChain(message.At(uid), message.Text("对方还没有牛牛呢,不能🤺")) jjLimiter.Delete(t) @@ -361,12 +363,12 @@ func init() { ctx.SendChain(message.Text(err)) return } - err = db.InsertNiuNiu(&u, gid) + err = db.insertNiuNiu(&u, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.InsertNiuNiu(&UserInfo{UID: adduser, Length: f1}, gid) + err = db.insertNiuNiu(&userInfo{UID: adduser, Length: f1}, gid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -401,6 +403,7 @@ func init() { if c.Count > 5 { ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count), "你们不要再找ta🤺啦!"}))) + // 保证只发生一次 if c.Count < 7 { id := ctx.SendPrivateMessage(adduser, message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid))) @@ -414,7 +417,7 @@ func init() { en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID gid := ctx.Event.GroupID - _, err := db.FindNiuNiu(gid, uid) + _, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("你还没有牛牛呢,咋的你想凭空造一个啊")) return diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index aa1a84bded..8d6e3b1b14 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -21,7 +21,7 @@ type model struct { sync.RWMutex } -type UserInfo struct { +type userInfo struct { UID int64 Length float64 UserCount int @@ -31,7 +31,7 @@ type UserInfo struct { ShenJi int // 击剑神稽 } -type users []*UserInfo +type users []*userInfo var ( db = &model{} @@ -47,7 +47,7 @@ var ( ) // useWeiGe 使用道具伟哥 -func (u *UserInfo) useWeiGe() (string, float64) { +func (u *userInfo) useWeiGe() (string, float64) { niuniu := u.Length reduce := math.Abs(hitGlue(niuniu)) niuniu += reduce @@ -59,7 +59,7 @@ func (u *UserInfo) useWeiGe() (string, float64) { } // usePhilter 使用道具媚药 -func (u *UserInfo) usePhilter() (string, float64) { +func (u *userInfo) usePhilter() (string, float64) { niuniu := u.Length reduce := math.Abs(hitGlue(niuniu)) niuniu -= reduce @@ -71,7 +71,7 @@ func (u *UserInfo) usePhilter() (string, float64) { } // useArtifact 使用道具击剑神器 -func (u *UserInfo) useArtifact(adduserniuniu float64) (string, float64, float64) { +func (u *userInfo) useArtifact(adduserniuniu float64) (string, float64, float64) { myLength := u.Length difference := myLength - adduserniuniu var ( @@ -93,7 +93,7 @@ func (u *UserInfo) useArtifact(adduserniuniu float64) (string, float64, float64) } // useShenJi 使用道具击剑神稽 -func (u *UserInfo) useShenJi(adduserniuniu float64) (string, float64, float64) { +func (u *userInfo) useShenJi(adduserniuniu float64) (string, float64, float64) { myLength := u.Length difference := myLength - adduserniuniu var ( @@ -125,7 +125,7 @@ func (u *UserInfo) useShenJi(adduserniuniu float64) (string, float64, float64) { } func (m users) positive() users { - var m1 []*UserInfo + var m1 []*userInfo for _, i2 := range m { if i2.Length > 0 { m1 = append(m1, i2) @@ -135,7 +135,7 @@ func (m users) positive() users { } func (m users) negative() users { - var m1 []*UserInfo + var m1 []*userInfo for _, i2 := range m { if i2.Length <= 0 { m1 = append(m1, i2) @@ -174,20 +174,20 @@ func (db *model) randLength() float64 { func (db *model) createGIDTable(gid int64) error { db.Lock() defer db.Unlock() - return db.sql.Create(strconv.FormatInt(gid, 10), &UserInfo{}) + return db.sql.Create(strconv.FormatInt(gid, 10), &userInfo{}) } -// FindNiuNiu 返回一个用户的牛牛信息 -func (db *model) FindNiuNiu(gid, uid int64) (UserInfo, error) { +// findNiuNiu 返回一个用户的牛牛信息 +func (db *model) findNiuNiu(gid, uid int64) (userInfo, error) { db.RLock() defer db.RUnlock() - u := UserInfo{} + u := userInfo{} err := db.sql.Find(strconv.FormatInt(gid, 10), &u, "where UID = "+strconv.FormatInt(uid, 10)) return u, err } -// InsertNiuNiu 更新一个用户的牛牛信息 -func (db *model) InsertNiuNiu(u *UserInfo, gid int64) error { +// insertNiuNiu 更新一个用户的牛牛信息 +func (db *model) insertNiuNiu(u *userInfo, gid int64) error { db.Lock() defer db.Unlock() return db.sql.Insert(strconv.FormatInt(gid, 10), u) @@ -202,6 +202,6 @@ func (db *model) deleteniuniu(gid, uid int64) error { func (db *model) readAllTable(gid int64) (users, error) { db.Lock() defer db.Unlock() - a, err := sql.FindAll[UserInfo](&db.sql, strconv.FormatInt(gid, 10), "where UserCount = 0") + a, err := sql.FindAll[userInfo](&db.sql, strconv.FormatInt(gid, 10), "where UserCount = 0") return a, err } diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 77d5bafce4..227c3aa9e7 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -9,15 +9,15 @@ import ( "time" ) -func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { +func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) { var ( - u UserInfo + u userInfo err error ) switch props { case "伟哥": if niuniu.WeiGe > 0 { - u = UserInfo{ + u = userInfo{ UID: niuniu.UID, Length: niuniu.Length, WeiGe: niuniu.WeiGe - 1, @@ -27,7 +27,7 @@ func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { } case "媚药": if niuniu.Philter > 0 { - u = UserInfo{ + u = userInfo{ UID: niuniu.UID, Length: niuniu.Length, Philter: niuniu.Philter - 1, @@ -37,7 +37,7 @@ func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { } case "击剑神器": if niuniu.Artifact > 0 { - u = UserInfo{ + u = userInfo{ UID: niuniu.UID, Length: niuniu.Length, Artifact: niuniu.Artifact - 1, @@ -47,7 +47,7 @@ func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { } case "击剑神稽": if niuniu.ShenJi > 0 { - u = UserInfo{ + u = userInfo{ UID: niuniu.UID, Length: niuniu.Length, ShenJi: niuniu.ShenJi - 1, @@ -61,60 +61,60 @@ func createUserInfoByProps(props string, niuniu *UserInfo) (UserInfo, error) { return u, err } -func processJJuAction(myniuniu, adduserniuniu *UserInfo, t string, props string) (string, float64, UserInfo, error) { +func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, userInfo, error) { var ( fencingResult string f float64 f1 float64 - u UserInfo + u userInfo err error ) v, ok := prop.Load(t) if props != "" { if props != "击剑神器" && props != "击剑神稽" { - return "", 0, UserInfo{}, errors.New("道具不存在") + return "", 0, userInfo{}, errors.New("道具不存在") } u, err = createUserInfoByProps(props, myniuniu) if err != nil { - return "", 0, UserInfo{}, err + return "", 0, userInfo{}, err } } switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = UserInfo{ + u = userInfo{ UID: myniuniu.UID, Length: f, } err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) case myniuniu.ShenJi-u.ShenJi != 0: fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) - u = UserInfo{ + u = userInfo{ UID: myniuniu.UID, Length: f, } updateMap(t, true) case myniuniu.Artifact-u.Artifact != 0: fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) - u = UserInfo{ + u = userInfo{ UID: myniuniu.UID, Length: f, } updateMap(t, true) default: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = UserInfo{ + u = userInfo{ UID: myniuniu.UID, Length: f, } } return fencingResult, f1, u, err } -func processNiuniuAction(t string, niuniu *UserInfo, props string) (string, UserInfo, error) { +func processNiuniuAction(t string, niuniu *userInfo, props string) (string, userInfo, error) { var ( messages string f float64 - u UserInfo + u userInfo err error ) load, ok := prop.Load(t) @@ -124,7 +124,7 @@ func processNiuniuAction(t string, niuniu *UserInfo, props string) (string, User } u, err = createUserInfoByProps(props, niuniu) if err != nil { - return "", UserInfo{}, err + return "", userInfo{}, err } } switch { @@ -149,40 +149,41 @@ func processNiuniuAction(t string, niuniu *UserInfo, props string) (string, User return messages, u, err } -func purchaseItem(n int, info UserInfo, uid int64) (*UserInfo, int, error) { +func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { var ( money int - u *UserInfo + u *userInfo + err error ) switch n { case 1: money = 300 - u = &UserInfo{ + u = &userInfo{ UID: uid, WeiGe: info.WeiGe + 5, } case 2: money = 300 - u = &UserInfo{ + u = &userInfo{ UID: uid, Philter: info.Philter + 5, } case 3: money = 500 - u = &UserInfo{ + u = &userInfo{ UID: uid, Artifact: info.Artifact + 2, } case 4: money = 500 - u = &UserInfo{ + u = &userInfo{ UID: uid, ShenJi: info.ShenJi + 2, } default: - return nil, 0, errors.New("无效的选项") + err = errors.New("无效的选择") } - return u, money, nil + return u, money, err } func generateRandomStingTwo(niuniu float64) (string, float64) { @@ -208,13 +209,12 @@ func generateRandomStingTwo(niuniu float64) (string, float64) { fmt.Sprintf("你突发恶疾!你的牛牛凹进去了%.2fcm!", reduce), fmt.Sprintf("笑死,你因为打🦶过度导致牛牛凹进去了%.2fcm!🤣🤣🤣", reduce), }), niuniu - } else { - return randomChoice([]string{ - fmt.Sprintf("阿哦,你过度打🦶,牛牛缩短%.2fcm了呢!", reduce), - fmt.Sprintf("你的牛牛变长了很多,你很激动地继续打🦶,然后牛牛缩短了%.2fcm呢!", reduce), - fmt.Sprintf("小打怡情,大打伤身,强打灰飞烟灭!你过度打🦶,牛牛缩短了%.2fcm捏!", reduce), - }), niuniu } + return randomChoice([]string{ + fmt.Sprintf("阿哦,你过度打🦶,牛牛缩短%.2fcm了呢!", reduce), + fmt.Sprintf("你的牛牛变长了很多,你很激动地继续打🦶,然后牛牛缩短了%.2fcm呢!", reduce), + fmt.Sprintf("小打怡情,大打伤身,强打灰飞烟灭!你过度打🦶,牛牛缩短了%.2fcm捏!", reduce), + }), niuniu } } From 2b4d380559df6b5b53b07e36ea8019013b6d3574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Sat, 21 Sep 2024 14:48:39 +0800 Subject: [PATCH 27/35] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/utils.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 227c3aa9e7..2878da9578 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -86,7 +86,7 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) UID: myniuniu.UID, Length: f, } - err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit))) + err = fmt.Errorf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) case myniuniu.ShenJi-u.ShenJi != 0: fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) u = userInfo{ @@ -132,7 +132,7 @@ func processNiuniuAction(t string, niuniu *userInfo, props string) (string, user messages, f = generateRandomStingTwo(niuniu.Length) u.Length = f u.UID = niuniu.UID - err = errors.New(fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit))) + err = fmt.Errorf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit)) case niuniu.WeiGe-u.WeiGe != 0: messages, f = niuniu.useWeiGe() u.Length = f From 531da5a47c2ed5750bf582440c0658c3d02eb19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Wed, 25 Sep 2024 23:06:28 +0800 Subject: [PATCH 28/35] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ plugin/niuniu/main.go | 77 +++++++++++++++++++++++++++--------------- plugin/niuniu/model.go | 4 +-- plugin/niuniu/utils.go | 74 ++++++++++------------------------------ 4 files changed, 70 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 83410c552b..dd04e69fa3 100644 --- a/README.md +++ b/README.md @@ -1045,6 +1045,8 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 牛牛商店 +- [x] 牛牛背包 + - [x] 注册牛牛 - [x] 注销牛牛 diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 2c40fd2a50..93660a91f9 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -34,9 +34,9 @@ var ( DisableOnDefault: false, Brief: "牛牛大作战", Help: "- 打胶\n" + - "使用[道具名称]打胶\n" + + "- 使用[道具名称]打胶\n" + "- jj@xxx\n" + - "使用[道具名称]jj@xxx\n" + + "- 使用[道具名称]jj@xxx\n" + "- 注册牛牛\n" + "- 赎牛牛(cd:45分钟)\n" + "- 牛牛商店\n" + @@ -62,15 +62,21 @@ func init() { ctx.SendChain(message.Text("你还没有牛牛呢快去注册一个吧!")) return } - ctx.SendChain(message.Text("当前牛牛背包如下\n", - "伟哥:", niu.WeiGe, + ctx.SendChain(message.Text("当前牛牛背包如下", + "\n伟哥:", niu.WeiGe, "\n媚药:", niu.Philter, "\n击剑神器:", niu.Artifact, "\n击剑神稽:", niu.ShenJi)) }) en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID - uid := ctx.Event.GroupID + uid := ctx.Event.UserID + + if _, err := db.findNiuNiu(gid, uid); err != nil { + ctx.SendChain(message.Text("你还没有牛牛呢快去注册一个吧!")) + return + } + var messages message.Message messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("牛牛商店当前售卖的物品如下"))) messages = append(messages, @@ -85,10 +91,12 @@ func init() { messages = append(messages, ctxext.FakeSenderForwardNode(ctx, message.Text("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次"))) + 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() defer cancel() @@ -107,32 +115,36 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } + info, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - u, money, err := purchaseItem(n, info, uid) + + u, money, err := purchaseItem(n, info) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + if wallet.GetWalletOf(uid) < money { ctx.SendChain(message.Text("你还没有足够的ATRI币呢,不能购买")) return } - err = wallet.InsertWalletOf(uid, -money) - if err != nil { + + if err = wallet.InsertWalletOf(uid, -money); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertNiuNiu(u, gid) - if err != nil { + + if err = db.insertNiuNiu(u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } ctx.SendChain(message.Text("购买成功!")) + return } } }) @@ -140,39 +152,47 @@ func init() { gid := ctx.Event.GroupID uid := ctx.Event.UserID last, ok := jjCount.Load(fmt.Sprintf("%d_%d", gid, uid)) + if !ok { ctx.SendChain(message.Text("你还没有被厥呢")) return } + if time.Since(last.TimeLimit) > time.Minute*45 { ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!")) jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } + if last.Count < 6 { ctx.SendChain(message.Text("你还没有被厥够6次呢,不能赎牛牛")) return } + money := wallet.GetWalletOf(uid) if money < 150 { ctx.SendChain(message.Text("赎牛牛需要150ATRI币,快去赚钱吧")) return } - err := wallet.InsertWalletOf(uid, -150) - if err != nil { + + if err := wallet.InsertWalletOf(uid, -150); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - u := &userInfo{ - UID: uid, - Length: last.Length, - UserCount: 0, - } - err = db.insertNiuNiu(u, gid) + + niuniu, err := db.findNiuNiu(gid, uid) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + + niuniu.Length = last.Length + + if err = db.insertNiuNiu(&niuniu, gid); err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) ctx.SendChain(message.At(uid), message.Text(fmt.Sprintf("恭喜你!成功赎回牛牛,当前长度为:%.2fcm", last.Length))) }) @@ -300,18 +320,18 @@ func init() { UserCount: 0, } // 添加数据进入表 - err := db.insertNiuNiu(&u, gid) - if err != nil { - err = db.createGIDTable(gid) - if err != nil { + if err := db.insertNiuNiu(&u, gid); err != nil { + + if err = db.createGIDTable(gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertNiuNiu(&u, gid) - if err != nil { + + if err = db.insertNiuNiu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + } ctx.SendChain(message.Reply(ctx.Event.GroupID), message.Text("注册成功,你的牛牛现在有", u.Length, "cm")) @@ -363,16 +383,17 @@ func init() { ctx.SendChain(message.Text(err)) return } - err = db.insertNiuNiu(&u, gid) - if err != nil { + + if err = db.insertNiuNiu(&u, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } - err = db.insertNiuNiu(&userInfo{UID: adduser, Length: f1}, gid) - if err != nil { + + if err = db.insertNiuNiu(&userInfo{UID: adduser, Length: f1}, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + ctx.SendChain(message.At(uid), message.Text(" ", fencingResult)) j := fmt.Sprintf("%d_%d", gid, adduser) count, ok := jjCount.Load(j) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 8d6e3b1b14..d33749482b 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -54,7 +54,7 @@ func (u *userInfo) useWeiGe() (string, float64) { return randomChoice([]string{ fmt.Sprintf("哈哈,你这一用道具,牛牛就像是被激发了潜能,增加了%.2fcm!看来今天是个大日子呢!", reduce), fmt.Sprintf("你这是用了什么神奇的道具?牛牛竟然增加了%.2fcm,简直是牛气冲天!", reduce), - fmt.Sprintf("“使用道具后,你的牛牛就像是开启了加速模式,一下增加了%.2fcm,这成长速度让人惊叹!", reduce), + fmt.Sprintf("使用道具后,你的牛牛就像是开启了加速模式,一下增加了%.2fcm,这成长速度让人惊叹!", reduce), }), niuniu } @@ -66,7 +66,7 @@ func (u *userInfo) usePhilter() (string, float64) { return randomChoice([]string{ fmt.Sprintf("你使用媚药,咿呀咿呀一下使当前长度发生了一些变化,当前长度%.2f", niuniu), fmt.Sprintf("看来你追求的是‘微观之美’,故意使用道具让牛牛凹进去了%.2fcm!", reduce), - fmt.Sprintf("‘缩小奇迹’在你身上发生了,牛牛凹进去了%.2fcm,你的选择真是独特!", reduce), + fmt.Sprintf("缩小奇迹’在你身上发生了,牛牛凹进去了%.2fcm,你的选择真是独特!", reduce), }), niuniu } diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 2878da9578..661842eb02 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -11,56 +11,41 @@ import ( func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) { var ( - u userInfo err error ) switch props { case "伟哥": if niuniu.WeiGe > 0 { - u = userInfo{ - UID: niuniu.UID, - Length: niuniu.Length, - WeiGe: niuniu.WeiGe - 1, - } + niuniu.WeiGe = niuniu.WeiGe - 1 } else { err = errors.New("你还没有伟哥呢,不能使用") } case "媚药": if niuniu.Philter > 0 { - u = userInfo{ - UID: niuniu.UID, - Length: niuniu.Length, - Philter: niuniu.Philter - 1, - } + niuniu.Philter = niuniu.Philter - 1 } else { err = errors.New("你还没有媚药呢,不能使用") } case "击剑神器": if niuniu.Artifact > 0 { - u = userInfo{ - UID: niuniu.UID, - Length: niuniu.Length, - Artifact: niuniu.Artifact - 1, - } + niuniu.Artifact = niuniu.Artifact - 1 } else { err = errors.New("你还没有击剑神器呢,不能使用") } case "击剑神稽": if niuniu.ShenJi > 0 { - u = userInfo{ - UID: niuniu.UID, - Length: niuniu.Length, - ShenJi: niuniu.ShenJi - 1, - } + niuniu.ShenJi = niuniu.ShenJi - 1 } else { err = errors.New("你还没有击剑神稽呢,不能使用") } default: err = errors.New("道具不存在") } - return u, err + return *niuniu, err } +// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称 +// 返回值依次是 要发生的消息 被jj用户的niuniu 用户的信息 错误信息 func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, userInfo, error) { var ( fencingResult string @@ -82,31 +67,19 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - } + u.Length = f err = fmt.Errorf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) case myniuniu.ShenJi-u.ShenJi != 0: fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - } + u.Length = f updateMap(t, true) case myniuniu.Artifact-u.Artifact != 0: fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - } + u.Length = f updateMap(t, true) default: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u = userInfo{ - UID: myniuniu.UID, - Length: f, - } + u.Length = f } return fencingResult, f1, u, err } @@ -149,41 +122,28 @@ func processNiuniuAction(t string, niuniu *userInfo, props string) (string, user return messages, u, err } -func purchaseItem(n int, info userInfo, uid int64) (*userInfo, int, error) { +func purchaseItem(n int, info userInfo) (*userInfo, int, error) { var ( money int - u *userInfo err error ) switch n { case 1: money = 300 - u = &userInfo{ - UID: uid, - WeiGe: info.WeiGe + 5, - } + info.WeiGe = info.WeiGe + 5 case 2: money = 300 - u = &userInfo{ - UID: uid, - Philter: info.Philter + 5, - } + info.Philter = info.Philter + 5 case 3: money = 500 - u = &userInfo{ - UID: uid, - Artifact: info.Artifact + 2, - } + info.Artifact = info.Artifact + 2 case 4: money = 500 - u = &userInfo{ - UID: uid, - ShenJi: info.ShenJi + 2, - } + info.ShenJi = info.ShenJi + 2 default: err = errors.New("无效的选择") } - return u, money, err + return &info, money, err } func generateRandomStingTwo(niuniu float64) (string, float64) { From 7f4adce867f4be8d8fca2394d4ca5a94a18a88ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Wed, 25 Sep 2024 23:16:52 +0800 Subject: [PATCH 29/35] =?UTF-8?q?=E4=BF=AElint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/utils.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 661842eb02..c6f5d4261a 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -16,25 +16,25 @@ func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) { switch props { case "伟哥": if niuniu.WeiGe > 0 { - niuniu.WeiGe = niuniu.WeiGe - 1 + niuniu.WeiGe-- } else { err = errors.New("你还没有伟哥呢,不能使用") } case "媚药": if niuniu.Philter > 0 { - niuniu.Philter = niuniu.Philter - 1 + niuniu.Philter-- } else { err = errors.New("你还没有媚药呢,不能使用") } case "击剑神器": if niuniu.Artifact > 0 { - niuniu.Artifact = niuniu.Artifact - 1 + niuniu.Artifact-- } else { err = errors.New("你还没有击剑神器呢,不能使用") } case "击剑神稽": if niuniu.ShenJi > 0 { - niuniu.ShenJi = niuniu.ShenJi - 1 + niuniu.ShenJi-- } else { err = errors.New("你还没有击剑神稽呢,不能使用") } @@ -68,7 +68,8 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) u.Length = f - err = fmt.Errorf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) + errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) + err = errors.New(errMessage) case myniuniu.ShenJi-u.ShenJi != 0: fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) u.Length = f @@ -105,7 +106,8 @@ func processNiuniuAction(t string, niuniu *userInfo, props string) (string, user messages, f = generateRandomStingTwo(niuniu.Length) u.Length = f u.UID = niuniu.UID - err = fmt.Errorf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit)) + errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit)) + err = errors.New(errMessage) case niuniu.WeiGe-u.WeiGe != 0: messages, f = niuniu.useWeiGe() u.Length = f @@ -130,16 +132,16 @@ func purchaseItem(n int, info userInfo) (*userInfo, int, error) { switch n { case 1: money = 300 - info.WeiGe = info.WeiGe + 5 + info.WeiGe += 5 case 2: money = 300 - info.Philter = info.Philter + 5 + info.Philter += 5 case 3: money = 500 - info.Artifact = info.Artifact + 2 + info.Artifact += 2 case 4: money = 500 - info.ShenJi = info.ShenJi + 2 + info.ShenJi += 2 default: err = errors.New("无效的选择") } From f9819c7c435dfe7ebfb3940b231c862ca8c06d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:14:42 +0800 Subject: [PATCH 30/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 18 +++++----- plugin/niuniu/utils.go | 74 ++++++++++++++++++++++-------------------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 93660a91f9..7af98503a1 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -294,13 +294,13 @@ func init() { dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid)) return } - messages, u, err := processNiuniuAction(t, &niuniu, fiancee[1]) + messages, err := processNiuniuAction(t, niuniu, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return } ctx.SendChain(message.Text(messages)) - if err = db.insertNiuNiu(&u, gid); err != nil { + if err = db.insertNiuNiu(&niuniu, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } @@ -313,11 +313,10 @@ func init() { return } // 获取初始长度 - long := db.randLength() + length := db.randLength() u := userInfo{ - UID: uid, - Length: long, - UserCount: 0, + UID: uid, + Length: length, } // 添加数据进入表 if err := db.insertNiuNiu(&u, gid); err != nil { @@ -378,18 +377,19 @@ func init() { jjLimiter.Delete(t) return } - fencingResult, f1, u, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1]) + fencingResult, f1, err := processJJuAction(myniuniu, adduserniuniu, t, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return } - if err = db.insertNiuNiu(&u, gid); err != nil { + if err = db.insertNiuNiu(&myniuniu, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } + adduserniuniu.Length = f1 - if err = db.insertNiuNiu(&userInfo{UID: adduser, Length: f1}, gid); err != nil { + if err = db.insertNiuNiu(&adduserniuniu, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) return } diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index c6f5d4261a..6282b19eee 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -9,7 +9,7 @@ import ( "time" ) -func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) { +func createUserInfoByProps(props string, niuniu userInfo) error { var ( err error ) @@ -41,12 +41,12 @@ func createUserInfoByProps(props string, niuniu *userInfo) (userInfo, error) { default: err = errors.New("道具不存在") } - return *niuniu, err + return err } // 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称 -// 返回值依次是 要发生的消息 被jj用户的niuniu 用户的信息 错误信息 -func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, userInfo, error) { +// 返回值依次是 要发生的消息 被jj用户的niuniu 错误信息 +func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) (string, float64, error) { var ( fencingResult string f float64 @@ -55,36 +55,36 @@ func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) err error ) v, ok := prop.Load(t) + u = myniuniu if props != "" { if props != "击剑神器" && props != "击剑神稽" { - return "", 0, userInfo{}, errors.New("道具不存在") + return "", 0, errors.New("道具不存在") } - u, err = createUserInfoByProps(props, myniuniu) - if err != nil { - return "", 0, userInfo{}, err + if err = createUserInfoByProps(props, myniuniu); err != nil { + return "", 0, err } } switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u.Length = f + myniuniu.Length = f errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) err = errors.New(errMessage) case myniuniu.ShenJi-u.ShenJi != 0: fencingResult, f, f1 = myniuniu.useShenJi(adduserniuniu.Length) - u.Length = f + myniuniu.Length = f updateMap(t, true) case myniuniu.Artifact-u.Artifact != 0: fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) - u.Length = f + myniuniu.Length = f updateMap(t, true) default: fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - u.Length = f + myniuniu.Length = f } - return fencingResult, f1, u, err + return fencingResult, f1, err } -func processNiuniuAction(t string, niuniu *userInfo, props string) (string, userInfo, error) { +func processNiuniuAction(t string, niuniu userInfo, props string) (string, error) { var ( messages string f float64 @@ -92,36 +92,41 @@ func processNiuniuAction(t string, niuniu *userInfo, props string) (string, user err error ) load, ok := prop.Load(t) + u = niuniu if props != "" { + if props != "伟哥" && props != "媚药" { - return "", u, errors.New("道具不存在") + return "", errors.New("道具不存在") } - u, err = createUserInfoByProps(props, niuniu) - if err != nil { - return "", userInfo{}, err + + if err = createUserInfoByProps(props, niuniu); err != nil { + return "", err } + } switch { case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: messages, f = generateRandomStingTwo(niuniu.Length) - u.Length = f - u.UID = niuniu.UID + niuniu.Length = f errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit)) err = errors.New(errMessage) + case niuniu.WeiGe-u.WeiGe != 0: messages, f = niuniu.useWeiGe() - u.Length = f + niuniu.Length = f updateMap(t, true) + case niuniu.Philter-u.Philter != 0: messages, f = niuniu.usePhilter() - u.Length = f + niuniu.Length = f updateMap(t, true) + default: messages, f = generateRandomStingTwo(niuniu.Length) - u.Length = f - u.UID = niuniu.UID + niuniu.Length = f + } - return messages, u, err + return messages, err } func purchaseItem(n int, info userInfo) (*userInfo, int, error) { @@ -244,19 +249,16 @@ func fencing(myLength, oppoLength float64) (string, float64, float64) { switch { case oppoLength <= -100 && myLength > 0 && 10 < probability && probability <= 20: - oppoLength *= 0.85 change := hitGlue(oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength))) - myLength = change + myLength += change return fmt.Sprintf("对方身为魅魔诱惑了你,你同化成魅魔!当前长度%.2fcm!", -myLength), -myLength, oppoLength case oppoLength >= 100 && myLength > 0 && 10 < probability && probability <= 20: - oppoLength *= 0.85 change := math.Min(math.Abs(devourLimit*myLength), math.Abs(1.5*myLength)) myLength += change return fmt.Sprintf("对方以牛头人的荣誉摧毁了你的牛牛!当前长度%.2fcm!", myLength), myLength, oppoLength case myLength <= -100 && oppoLength > 0 && 10 < probability && probability <= 20: - myLength *= 0.85 change := hitGlue(myLength+oppoLength) + rand.Float64()*math.Log2(math.Abs(0.5*(myLength+oppoLength))) oppoLength -= change myLength -= change @@ -277,20 +279,17 @@ func determineResultBySkill(myLength, oppoLength float64) (string, float64, floa probability := rand.Intn(100) + 1 winProbability := calculateWinProbability(myLength, oppoLength) * 100 return applySkill(myLength, oppoLength, - 0 < probability && float64(probability) <= winProbability) + float64(probability) <= winProbability) } // calculateWinProbability 计算胜率 func calculateWinProbability(heightA, heightB float64) float64 { - var pA float64 - if heightA > heightB { - pA = 0.7 + 0.2*(heightA-heightB)/heightA - } else { - pA = 0.7 - 0.2*(heightB-heightA)/heightB - } + // 选手 A 的初始胜率为 90% + pA := 0.9 heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB) reductionRate := 0.1 * (heightRatio - 1) reduction := pA * reductionRate + adjustedPA := pA - reduction return math.Max(adjustedPA, 0.01) } @@ -298,6 +297,9 @@ func calculateWinProbability(heightA, heightB float64) float64 { // applySkill 应用击剑技巧并生成结果 func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, float64, float64) { reduce := fence(oppoLength) + if reduce == 0 { + reduce = rand.Float64() + float64(rand.Intn(3)) + } if increaseLength1 { myLength += reduce oppoLength -= 0.8 * reduce From 185f857a9c46004b9ca6dea6c7aa642e9657da98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:16:19 +0800 Subject: [PATCH 31/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 2 +- plugin/niuniu/utils.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 7af98503a1..f94160d0d9 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -332,7 +332,7 @@ func init() { } } - ctx.SendChain(message.Reply(ctx.Event.GroupID), + ctx.SendChain(message.At(uid), message.Text("注册成功,你的牛牛现在有", u.Length, "cm")) }) en.OnRegex(`^(?:.*使用(.*))??jj\s?(\[CQ:at,(?:\S*,)?qq=(\d+)(?:,\S*)?\]|(\d+))$`, getdb, diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 6282b19eee..ef2523ee33 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -286,6 +286,7 @@ func determineResultBySkill(myLength, oppoLength float64) (string, float64, floa func calculateWinProbability(heightA, heightB float64) float64 { // 选手 A 的初始胜率为 90% pA := 0.9 + heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB) reductionRate := 0.1 * (heightRatio - 1) reduction := pA * reductionRate From 9b9a17f4484089804ce394c6f38709e4eece132b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:18:43 +0800 Subject: [PATCH 32/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 1 + plugin/niuniu/utils.go | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index f94160d0d9..dedc7a055c 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -461,6 +461,7 @@ func updateMap(t string, d bool) { if value == nil { return } + // 检查一次是否已经过期 if !d { if time.Since(value.TimeLimit) > time.Minute*8 { prop.Delete(t) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index ef2523ee33..287c4ac4a4 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -284,9 +284,7 @@ func determineResultBySkill(myLength, oppoLength float64) (string, float64, floa // calculateWinProbability 计算胜率 func calculateWinProbability(heightA, heightB float64) float64 { - // 选手 A 的初始胜率为 90% pA := 0.9 - heightRatio := math.Max(heightA, heightB) / math.Min(heightA, heightB) reductionRate := 0.1 * (heightRatio - 1) reduction := pA * reductionRate From 9ce8dc275a9945b12db178717e9e29d99288b6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:25:24 +0800 Subject: [PATCH 33/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 2 ++ plugin/niuniu/utils.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index dedc7a055c..d9ad3dc886 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -18,12 +18,14 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" ) +// 赎牛牛 type lastLength struct { TimeLimit time.Time Count int Length float64 } +// 牛牛商店 type propsCount struct { Count int TimeLimit time.Time diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 287c4ac4a4..1a06e00315 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -45,7 +45,7 @@ func createUserInfoByProps(props string, niuniu userInfo) error { } // 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称 -// 返回值依次是 要发生的消息 被jj用户的niuniu 错误信息 +// 返回值依次是 要发生的消息 错误信息 func processJJuAction(myniuniu, adduserniuniu userInfo, t string, props string) (string, float64, error) { var ( fencingResult string From d68d6af37a6d7c64ed52fde926632c08e55c840c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:27:30 +0800 Subject: [PATCH 34/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 1a06e00315..38acb26341 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -317,7 +317,7 @@ func applySkill(myLength, oppoLength float64, increaseLength1 bool) (string, flo } -// fence +// fence 根据长度计算减少的长度 func fence(rd float64) float64 { r := hitGlue(rd)*2 + rand.Float64()*math.Log2(rd) if rand.Intn(2) == 1 { From 05e18c7e4a45b6c1c5f99f9a0b0551d33b8170cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87=E5=AE=87?= <3061196825@qq.com> Date: Thu, 26 Sep 2024 23:27:55 +0800 Subject: [PATCH 35/35] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/niuniu/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index d9ad3dc886..dedc7a055c 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -18,14 +18,12 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" ) -// 赎牛牛 type lastLength struct { TimeLimit time.Time Count int Length float64 } -// 牛牛商店 type propsCount struct { Count int TimeLimit time.Time