Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改牛牛排行为图片发送 #1024

Merged
merged 25 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions plugin/niuniu/draw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package niuniu

import (
"fmt"
"github.com/FloatTech/floatbox/file"
"github.com/FloatTech/rendercard"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/img/text"
"image"
"net/http"
)

type drawUserRanking struct {
name string
User *userInfo
fumiama marked this conversation as resolved.
Show resolved Hide resolved
}

fumiama marked this conversation as resolved.
Show resolved Hide resolved
type drawer []drawUserRanking

func (allUsers drawer) draw(t bool) (img image.Image, err error) {
fontbyte, err := file.GetLazyData(text.GlowSansFontFile, control.Md5File, true)
if err != nil {
return nil, err
}
var (
title string
s string
)
title = "牛牛深度排行"
s = "牛牛深度"
if t {
title = "牛牛长度排行"
s = "牛牛长度"
}
ri := make([]*rendercard.RankInfo, len(allUsers))
for i, user := range allUsers {
resp, err := http.Get(fmt.Sprintf("https://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)
fumiama marked this conversation as resolved.
Show resolved Hide resolved
_ = resp.Body.Close()
if err != nil {
return nil, err
}
ri[i] = &rendercard.RankInfo{
Avatar: decode,
TopLeftText: user.name,
BottomLeftText: fmt.Sprintf("QQ:%d", user.User.UID),
RightText: fmt.Sprintf("%s:%.2fcm", s, user.User.Length),
}
}
img, err = rendercard.DrawRankingCard(fontbyte, title, ri)
return
}
102 changes: 46 additions & 56 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
package niuniu

import (
"bytes"
"fmt"
"math/rand"
"image/png"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -38,7 +39,7 @@ var (
"- jj@xxx\n" +
"- 使用[道具名称]jj@xxx\n" +
"- 注册牛牛\n" +
"- 赎牛牛(cd:45分钟)\n" +
"- 赎牛牛(cd:60分钟)\n" +
"- 牛牛商店\n" +
"- 牛牛背包\n" +
"- 注销牛牛\n" +
Expand Down Expand Up @@ -158,14 +159,14 @@ func init() {
return
}

if time.Since(last.TimeLimit) > time.Minute*45 {
if time.Since(last.TimeLimit) > time.Minute*60 {
ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!"))
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
}

if last.Count < 6 {
ctx.SendChain(message.Text("你还没有被厥够6次呢,不能赎牛牛"))
if last.Count < 4 {
ctx.SendChain(message.Text("你还没有被厥够4次呢,不能赎牛牛"))
return
}

Expand Down Expand Up @@ -208,16 +209,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)
allUsers := make(drawer, len(m))
for i, info := range m {
allUsers[i] = drawUserRanking{
name: ctx.CardOrNickName(info.UID),
User: info,
}
}
ranking, err := allUsers.draw(true)
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("牛子深度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
Expand All @@ -231,16 +243,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)
fumiama marked this conversation as resolved.
Show resolved Hide resolved
allUsers := make(drawer, len(m))
for i, info := range m {
allUsers[i] = drawUserRanking{
name: ctx.CardOrNickName(info.UID),
User: info,
}
}
ranking, err := allUsers.draw(false)
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
Expand Down Expand Up @@ -411,7 +433,7 @@ func init() {
Count: count.Count + 1,
Length: count.Length,
}
if time.Since(c.TimeLimit) > time.Minute*45 {
if time.Since(c.TimeLimit) > time.Minute*60 {
c = lastLength{
TimeLimit: time.Now(),
Count: 1,
Expand All @@ -421,11 +443,11 @@ func init() {
}

jjCount.Store(j, &c)
if c.Count > 5 {
if c.Count > 2 {
ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count),
"你们不要再找ta🤺啦!"})))
// 保证只发送一次
if c.Count < 7 {
if c.Count < 4 {
id := ctx.SendPrivateMessage(adduser,
message.Text(fmt.Sprintf("你在%d群里已经被厥冒烟了,快去群里赎回你原本的牛牛!\n发送:`赎牛牛`即可!", gid)))
if id == 0 {
Expand All @@ -450,35 +472,3 @@ func init() {
ctx.SendChain(message.Text("注销成功,你已经没有牛牛了"))
})
}

func randomChoice(options []string) string {
return options[rand.Intn(len(options))]
}

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)
}
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)
}
}
7 changes: 3 additions & 4 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -305,12 +305,11 @@ 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(niuniu > 0)
for i, user := range m {
if user.UID == uid {
return i + 1
}
Expand Down
53 changes: 43 additions & 10 deletions plugin/niuniu/utils.go
fumiama marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,56 @@ import (
"math"
"math/rand"
"strings"
"time"
)

var (
jjProp = []string{"击剑神器", "击剑神稽"}
dajiaoProp = []string{"伟哥", "媚药"}
)

// 检查字符串是否在切片中
func contains(s string, array []string) bool {
for _, item := range array {
if strings.EqualFold(item, s) {
return true
}
}
return false
}

func randomChoice(options []string) string {
return options[rand.Intn(len(options))]
}

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)
}
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)
}
}

func generateRandomStingTwo(niuniu float64) (string, float64) {
probability := rand.Intn(100 + 1)
reduce := math.Abs(hitGlue(niuniu))
Expand Down Expand Up @@ -205,13 +248,3 @@ 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
}
Loading