From c15420bd77c677e80d0f26411d8027224f3790ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:12:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix=E7=89=9B=E7=89=9B=E9=80=BB=E8=BE=91?= =?UTF-8?q?=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 | 9 ++- plugin/niuniu/model.go | 148 ++++++++++++++++++++++++++++++++++++++ plugin/niuniu/utils.go | 157 ++++------------------------------------- 3 files changed, 167 insertions(+), 147 deletions(-) diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index 22d7cb33cc..e00c66115f 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -122,7 +122,7 @@ func init() { return } - money, err := purchaseItem(n, info) + money, err := info.purchaseItem(n) if err != nil { ctx.SendChain(message.Text("ERROR:", err)) return @@ -296,7 +296,7 @@ func init() { return } - messages, err := processNiuniuAction(t, &niuniu, fiancee[1]) + messages, err := niuniu.processNiuNiuAction(t, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return @@ -378,7 +378,7 @@ func init() { jjLimiter.Delete(t) return } - fencingResult, f1, err := processJJuAction(&myniuniu, &adduserniuniu, t, fiancee[1]) + fencingResult, err := myniuniu.processJJuAction(&adduserniuniu, t, fiancee[1]) if err != nil { ctx.SendChain(message.Text(err)) return @@ -388,7 +388,6 @@ func init() { ctx.SendChain(message.Text("ERROR:", err)) return } - adduserniuniu.Length = f1 if err = db.insertNiuNiu(&adduserniuniu, gid); err != nil { ctx.SendChain(message.Text("ERROR:", err)) @@ -425,7 +424,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))) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index a3d444555d..f9ea50918c 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -2,6 +2,7 @@ package niuniu import ( + "errors" "fmt" "math" "math/rand" @@ -129,6 +130,153 @@ func (u *userInfo) useShenJi(adduserniuniu float64) (string, float64, float64) { return r, myLength, adduserniuniu + 0.7*change } +func (u *userInfo) processNiuNiuAction(t string, props string) (string, error) { + var ( + messages string + info userInfo + err error + f float64 + ) + load, ok := prop.Load(t) + info = *u + if props != "" { + if contains(props, dajiaoProp) { + if err = u.createUserInfoByProps(props); err != nil { + return "", err + } + } else { + return "", errors.New("道具不能混着用哦") + } + } + switch { + case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: + messages, f = generateRandomStingTwo(u.Length) + u.Length = f + errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(load.TimeLimit)) + err = errors.New(errMessage) + + case u.WeiGe-info.WeiGe != 0: + messages, f = u.useWeiGe() + u.Length = f + updateMap(t, true) + + case u.Philter-info.Philter != 0: + messages, f = u.usePhilter() + u.Length = f + updateMap(t, true) + + default: + messages, f = generateRandomStingTwo(u.Length) + u.Length = f + } + return messages, err +} + +func (u *userInfo) createUserInfoByProps(props string) error { + var ( + err error + ) + switch props { + case "伟哥": + if u.WeiGe > 0 { + u.WeiGe-- + } else { + err = errors.New("你还没有伟哥呢,不能使用") + } + case "媚药": + if u.Philter > 0 { + u.Philter-- + } else { + err = errors.New("你还没有媚药呢,不能使用") + } + case "击剑神器": + if u.Artifact > 0 { + u.Artifact-- + } else { + err = errors.New("你还没有击剑神器呢,不能使用") + } + case "击剑神稽": + if u.ShenJi > 0 { + u.ShenJi-- + } else { + err = errors.New("你还没有击剑神稽呢,不能使用") + } + default: + err = errors.New("道具不存在") + } + return err +} + +// 接收值依次是 被jj用户的信息 记录gid和uid的字符串 道具名称 +// 返回值依次是 要发送的消息 错误信息 +func (u *userInfo) processJJuAction(adduserniuniu *userInfo, t string, props string) (string, error) { + var ( + fencingResult string + f float64 + f1 float64 + info userInfo + err error + ) + v, ok := prop.Load(t) + info = *u + if props != "" { + if contains(t, jjProp) { + if err = u.createUserInfoByProps(props); err != nil { + return "", err + } + } else { + return "", errors.New("道具不能混着用哦") + } + } + switch { + case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: + fencingResult, f, f1 = fencing(u.Length, adduserniuniu.Length) + u.Length = f + adduserniuniu.Length = f1 + errMessage := fmt.Sprintf("你使用道具次数太快了,此次道具不会生效,等待%d再来吧", time.Minute*8-time.Since(v.TimeLimit)) + err = errors.New(errMessage) + case u.ShenJi-info.ShenJi != 0: + fencingResult, f, f1 = u.useShenJi(adduserniuniu.Length) + u.Length = f + adduserniuniu.Length = f1 + updateMap(t, true) + case u.Artifact-info.Artifact != 0: + fencingResult, f, f1 = u.useArtifact(adduserniuniu.Length) + u.Length = f + adduserniuniu.Length = f1 + updateMap(t, true) + default: + fencingResult, f, f1 = fencing(u.Length, adduserniuniu.Length) + u.Length = f + adduserniuniu.Length = f1 + } + return fencingResult, err +} + +func (u *userInfo) purchaseItem(n int) (int, error) { + var ( + money int + err error + ) + switch n { + case 1: + money = 300 + u.WeiGe += 5 + case 2: + money = 300 + u.Philter += 5 + case 3: + money = 500 + u.Artifact += 2 + case 4: + money = 500 + u.ShenJi += 2 + default: + err = errors.New("无效的选择") + } + return money, err +} + func (m users) positive() users { var m1 []*userInfo for _, i2 := range m { diff --git a/plugin/niuniu/utils.go b/plugin/niuniu/utils.go index 5e41f06615..1af733af5a 100644 --- a/plugin/niuniu/utils.go +++ b/plugin/niuniu/utils.go @@ -2,153 +2,16 @@ package niuniu import ( - "errors" "fmt" "math" "math/rand" - "time" + "strings" ) -func createUserInfoByProps(props string, niuniu *userInfo) error { - var ( - err error - ) - switch props { - case "伟哥": - if niuniu.WeiGe > 0 { - niuniu.WeiGe-- - } else { - err = errors.New("你还没有伟哥呢,不能使用") - } - case "媚药": - if niuniu.Philter > 0 { - niuniu.Philter-- - } else { - err = errors.New("你还没有媚药呢,不能使用") - } - case "击剑神器": - if niuniu.Artifact > 0 { - niuniu.Artifact-- - } else { - err = errors.New("你还没有击剑神器呢,不能使用") - } - case "击剑神稽": - if niuniu.ShenJi > 0 { - niuniu.ShenJi-- - } else { - err = errors.New("你还没有击剑神稽呢,不能使用") - } - default: - err = errors.New("道具不存在") - } - return err -} - -// 接收值依次是 自己和被jj用户的信息 一个包含gid和uid的字符串 道具名称 -// 返回值依次是 要发生的消息 错误信息 -func processJJuAction(myniuniu, adduserniuniu *userInfo, t string, props string) (string, float64, error) { - var ( - fencingResult string - f float64 - f1 float64 - u userInfo - err error - ) - v, ok := prop.Load(t) - u = *myniuniu - if props != "" { - if props != "击剑神器" && props != "击剑神稽" { - return "", 0, errors.New("道具不存在") - } - 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) - 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) - myniuniu.Length = f - updateMap(t, true) - case myniuniu.Artifact-u.Artifact != 0: - fencingResult, f, f1 = myniuniu.useArtifact(adduserniuniu.Length) - myniuniu.Length = f - updateMap(t, true) - default: - fencingResult, f, f1 = fencing(myniuniu.Length, adduserniuniu.Length) - myniuniu.Length = f - } - return fencingResult, f1, err -} -func processNiuniuAction(t string, niuniu *userInfo, props string) (string, error) { - var ( - messages string - u userInfo - err error - f float64 - ) - load, ok := prop.Load(t) - u = *niuniu - if props != "" { - if props != "伟哥" && props != "媚药" { - return "", errors.New("道具不存在") - } - - 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) - 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() - niuniu.Length = f - updateMap(t, true) - - case niuniu.Philter-u.Philter != 0: - messages, f = niuniu.usePhilter() - niuniu.Length = f - updateMap(t, true) - - default: - messages, f = generateRandomStingTwo(niuniu.Length) - niuniu.Length = f - } - return messages, err -} - -func purchaseItem(n int, info userInfo) (int, error) { - var ( - money int - err error - ) - switch n { - case 1: - money = 300 - info.WeiGe += 5 - case 2: - money = 300 - info.Philter += 5 - case 3: - money = 500 - info.Artifact += 2 - case 4: - money = 500 - info.ShenJi += 2 - default: - err = errors.New("无效的选择") - } - return money, err -} +var ( + jjProp = []string{"击剑神器", "击剑神稽"} + dajiaoProp = []string{"伟哥", "媚药"} +) func generateRandomStingTwo(niuniu float64) (string, float64) { probability := rand.Intn(100 + 1) @@ -342,3 +205,13 @@ func hitGlue(l float64) float64 { return rand.Float64() } } + +// 检查字符串是否在切片中 +func contains(s string, array []string) bool { + for _, item := range array { + if strings.EqualFold(item, s) { + return true + } + } + return false +} From 6c6a049d9e4ac6867338d527336f5d4347962ade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:16:16 +0800 Subject: [PATCH 2/5] fix --- plugin/niuniu/model.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index f9ea50918c..8841e0a016 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -140,13 +140,12 @@ func (u *userInfo) processNiuNiuAction(t string, props string) (string, error) { load, ok := prop.Load(t) info = *u if props != "" { - if contains(props, dajiaoProp) { - if err = u.createUserInfoByProps(props); err != nil { - return "", err - } - } else { + if !contains(t, jjProp) { return "", errors.New("道具不能混着用哦") } + if err = u.createUserInfoByProps(props); err != nil { + return "", err + } } switch { case ok && load.Count > 1 && time.Since(load.TimeLimit) < time.Minute*8: @@ -220,13 +219,12 @@ func (u *userInfo) processJJuAction(adduserniuniu *userInfo, t string, props str v, ok := prop.Load(t) info = *u if props != "" { - if contains(t, jjProp) { - if err = u.createUserInfoByProps(props); err != nil { - return "", err - } - } else { + if !contains(t, jjProp) { return "", errors.New("道具不能混着用哦") } + if err = u.createUserInfoByProps(props); err != nil { + return "", err + } } switch { case ok && v.Count > 1 && time.Since(v.TimeLimit) < time.Minute*8: From d318ecd2e1cda13e14c99441427bd66c1b6dc17c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 6 Oct 2024 15:22:19 +0800 Subject: [PATCH 3/5] fix --- plugin/niuniu/model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 8841e0a016..9d1ce95e8a 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -140,7 +140,7 @@ func (u *userInfo) processNiuNiuAction(t string, props string) (string, error) { load, ok := prop.Load(t) info = *u if props != "" { - if !contains(t, jjProp) { + if !contains(t, dajiaoProp) { return "", errors.New("道具不能混着用哦") } if err = u.createUserInfoByProps(props); err != nil { From a9ee34b5cfd77411e1af61bfacaabc0f5c33e9be 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, 13 Oct 2024 15:08:26 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=9B=E7=89=9B?= =?UTF-8?q?=E6=8E=92=E5=90=8D=E4=B8=BA=E5=9B=BE=E7=89=87=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 +- plugin/niuniu/main.go | 112 ++++++++++++++++++++++++++++------------- plugin/niuniu/model.go | 8 ++- 4 files changed, 84 insertions(+), 42 deletions(-) diff --git a/go.mod b/go.mod index d5295da37f..0a134af14b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/FloatTech/floatbox v0.0.0-20240505082030-226ec6713e14 github.com/FloatTech/gg v1.1.3 github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef - github.com/FloatTech/rendercard v0.1.1 + github.com/FloatTech/rendercard v0.1.2 github.com/FloatTech/sqlite v1.6.3 github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb diff --git a/go.sum b/go.sum index 9ddb076866..d02a9571e0 100644 --- a/go.sum +++ b/go.sum @@ -9,8 +9,8 @@ github.com/FloatTech/gg v1.1.3 h1:+GlL02lTKsxJQr4WCuNwVxC1/eBZrCvypCIBtxuOFb4= github.com/FloatTech/gg v1.1.3/go.mod h1:/9oLP54CMfq4r+71XL26uaFTJ1uL1boAyX67680/1HE= github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef h1:CJbK/2FRwPuZpeb6M4sWK2d7oXDnBEGhpkQuQrgc91A= github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef/go.mod h1:el5hGpj1C1bDRxcTXYRwEivDCr40zZeJpcrLrB1fajs= -github.com/FloatTech/rendercard v0.1.1 h1:vXz3x92bLavmNexTywdUvhft2/ipUSuo8aPRkqVdGQ8= -github.com/FloatTech/rendercard v0.1.1/go.mod h1:Sbojcy1t3NfFz7/WicZRmR/uKFxNMYkKF8qHx69dxY0= +github.com/FloatTech/rendercard v0.1.2 h1:W4SF9fSxv6Ava+kIUI0T1ILOjId/cgZ0huuEpMpHJbU= +github.com/FloatTech/rendercard v0.1.2/go.mod h1:Sbojcy1t3NfFz7/WicZRmR/uKFxNMYkKF8qHx69dxY0= github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4M= github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ/VCf80LiQo9C7jHgrunZDwiRcY= diff --git a/plugin/niuniu/main.go b/plugin/niuniu/main.go index e00c66115f..feb2d4e2d4 100644 --- a/plugin/niuniu/main.go +++ b/plugin/niuniu/main.go @@ -2,7 +2,9 @@ package niuniu import ( + "bytes" "fmt" + "image/png" "math/rand" "strconv" "strings" @@ -151,7 +153,8 @@ 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.Load(fmt.Sprintf("%d_%d", gid, uid)) + t := fmt.Sprintf("%d_%d", gid, uid) + last, ok := jjCount.Load(t) if !ok { ctx.SendChain(message.Text("你还没有被厥呢")) @@ -160,7 +163,7 @@ func init() { if time.Since(last.TimeLimit) > time.Minute*45 { ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!")) - jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid)) + jjCount.Delete(t) return } @@ -174,27 +177,47 @@ func init() { ctx.SendChain(message.Text("赎牛牛需要150ATRI币,快去赚钱吧")) return } + ctx.SendChain(message.Text(message.Text("赎牛牛后长度会变为:", last.Length, "cm,是否要这样做吗?【是|否】"))) + recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`^(是|否)$`)).Repeat() + defer cancel() + timer := time.NewTimer(2 * time.Minute) + defer timer.Stop() + for { + select { + case <-timer.C: + ctx.SendChain(message.At(uid), message.Text("回答超时已自动取消")) + return + case r := <-recv: + answer := r.Event.Message.String() - if err := wallet.InsertWalletOf(uid, -150); err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } + if answer == "否" { + ctx.SendChain(message.Text("已销毁牛牛!")) + jjCount.Delete(t) + return + } - niuniu, err := db.findNiuNiu(gid, uid) - if err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } + if err := wallet.InsertWalletOf(uid, -150); err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + + niuniu, err := db.findNiuNiu(gid, uid) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } - niuniu.Length = last.Length + niuniu.Length = last.Length - if err = db.insertNiuNiu(&niuniu, gid); err != nil { - ctx.SendChain(message.Text("ERROR:", err)) - return - } + 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))) + 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) { gid := ctx.Event.GroupID @@ -208,16 +231,27 @@ func init() { ctx.SendChain(message.Text("暂时没有男孩子哦")) return } - var messages strings.Builder - 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)) + m.sort(true) + var allUsers []drawUserRanking + for _, info := range m { + allUsers = append(allUsers, drawUserRanking{ + Name: ctx.CardOrNickName(info.UID), + User: info, + }) } - msg := ctxext.FakeSenderForwardNode(ctx, message.Text(&messages)) - if id := ctx.Send(message.Message{msg}).ID(); id == 0 { - ctx.Send(message.Text("发送排行失败")) + ranking, err := drawRanking(allUsers, "牛牛长度排行") + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return } + var buf bytes.Buffer + err = png.Encode(&buf, ranking) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return + } + ctx.SendChain(message.ImageBytes(buf.Bytes())) + }) en.OnFullMatch("牛子深度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) { gid := ctx.Event.GroupID @@ -231,16 +265,26 @@ func init() { ctx.SendChain(message.Text("暂时没有女孩子哦")) return } - var messages strings.Builder - messages.WriteString("牛牛深度排行榜\n") - for i, user := range m.sort(false) { - messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1, - ctx.CardOrNickName(user.UID), user.Length)) + m.sort(false) + var allUsers []drawUserRanking + for _, info := range m { + allUsers = append(allUsers, drawUserRanking{ + Name: ctx.CardOrNickName(info.UID), + User: info, + }) + } + ranking, err := drawRanking(allUsers, "牛牛深度排行") + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return } - msg := ctxext.FakeSenderForwardNode(ctx, message.Text(&messages)) - if id := ctx.Send(message.Message{msg}).ID(); id == 0 { - ctx.Send(message.Text("发送排行失败")) + var buf bytes.Buffer + err = png.Encode(&buf, ranking) + if err != nil { + ctx.SendChain(message.Text("ERROR:", err)) + return } + ctx.SendChain(message.ImageBytes(buf.Bytes())) }) en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID diff --git a/plugin/niuniu/model.go b/plugin/niuniu/model.go index 9d1ce95e8a..e4c85be9db 100644 --- a/plugin/niuniu/model.go +++ b/plugin/niuniu/model.go @@ -295,7 +295,7 @@ func (m users) negative() users { return m1 } -func (m users) sort(isDesc bool) users { +func (m users) sort(isDesc bool) { t := func(i, j int) bool { return m[i].Length < m[j].Length } @@ -305,12 +305,12 @@ func (m users) sort(isDesc bool) users { } } sort.Slice(m, t) - return m } func (m users) ranking(niuniu float64, uid int64) int { result := niuniu > 0 - for i, user := range m.sort(result) { + m.sort(result) + for i, user := range m { if user.UID == uid { return i + 1 } @@ -328,7 +328,6 @@ func (db *model) createGIDTable(gid int64) error { return db.sql.Create(strconv.FormatInt(gid, 10), &userInfo{}) } -// findNiuNiu 返回一个用户的牛牛信息 func (db *model) findNiuNiu(gid, uid int64) (userInfo, error) { db.RLock() defer db.RUnlock() @@ -337,7 +336,6 @@ func (db *model) findNiuNiu(gid, uid int64) (userInfo, error) { return u, err } -// insertNiuNiu 更新一个用户的牛牛信息 func (db *model) insertNiuNiu(u *userInfo, gid int64) error { db.Lock() defer db.Unlock() From 53be80794a3c49ae285a887676986e3abd93c156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=7E?= <158024940+xyy0411@users.noreply.github.com> Date: Sun, 13 Oct 2024 15:12:21 +0800 Subject: [PATCH 5/5] Add files via upload --- plugin/niuniu/draw.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 plugin/niuniu/draw.go diff --git a/plugin/niuniu/draw.go b/plugin/niuniu/draw.go new file mode 100644 index 0000000000..58a1333ab1 --- /dev/null +++ b/plugin/niuniu/draw.go @@ -0,0 +1,38 @@ +package niuniu + +import ( + "fmt" + "github.com/FloatTech/rendercard" + "image" + "net/http" + "os" +) + +var font, _ = os.ReadFile("./font/GlowSans.otf") + +type drawUserRanking struct { + Name string + User *userInfo +} + +func drawRanking(allUsers []drawUserRanking, title string) (img image.Image, err error) { + var ri []*rendercard.RankInfo + for _, user := range allUsers { + resp, err := http.Get(fmt.Sprintf("http://q1.qlogo.cn/g?b=qq&nk=%d&s=100", user.User.UID)) + if err != nil { + return nil, err + } + decode, _, err := image.Decode(resp.Body) + if err != nil { + return nil, err + } + ri = append(ri, &rendercard.RankInfo{ + Avatar: decode, + TopLeftText: user.Name, + BottomLeftText: fmt.Sprintf("QQ:%d", user.User.UID), + RightText: fmt.Sprintf("牛牛长度:%.2fcm", user.User.Length), + }) + } + img, err = rendercard.DrawRankingCard(font, title, ri) + return +}