Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
xyy0411 authored Oct 20, 2024
1 parent 8cd34b3 commit c6dcc9b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 36 deletions.
8 changes: 4 additions & 4 deletions plugin/niuniu/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

type drawUserRanking struct {
name string
User *userInfo
user *userInfo
}

type drawer []drawUserRanking
Expand All @@ -34,7 +34,7 @@ func (allUsers drawer) draw(t bool) (img image.Image, err error) {
}
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))
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
}
Expand All @@ -46,8 +46,8 @@ func (allUsers drawer) draw(t bool) (img image.Image, err error) {
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),
BottomLeftText: fmt.Sprintf("QQ:%d", user.user.UID),
RightText: fmt.Sprintf("%s:%.2fcm", s, user.user.Length),
}
}
img, err = rendercard.DrawRankingCard(fontbyte, title, ri)
Expand Down
37 changes: 5 additions & 32 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
package niuniu

import (
"bytes"
"fmt"
"image/png"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -210,25 +208,12 @@ func init() {
return
}
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)
buf, err := m.setupDrawList(ctx, true)
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()))
ctx.SendChain(message.ImageBytes(buf))

})
en.OnFullMatch("牛子深度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
Expand All @@ -244,25 +229,13 @@ func init() {
return
}
m.sort(false)
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
}
var buf bytes.Buffer
err = png.Encode(&buf, ranking)
buf, err := m.setupDrawList(ctx, false)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
ctx.SendChain(message.ImageBytes(buf.Bytes()))

ctx.SendChain(message.ImageBytes(buf))
})
en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand Down
19 changes: 19 additions & 0 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
package niuniu

import (
"bytes"
"errors"
"fmt"
"image/png"
"math"
"math/rand"
"sort"
Expand Down Expand Up @@ -275,6 +277,23 @@ func (u *userInfo) purchaseItem(n int) (int, error) {
return money, err
}

func (m users) setupDrawList(ctx *zero.Ctx, t bool) ([]byte, error) {
allUsers := make(drawer, len(m))
for i, info := range m {
allUsers[i] = drawUserRanking{
name: ctx.CardOrNickName(info.UID),
user: info,
}
}
image, err := allUsers.draw(t)
if err != nil {
return nil, err
}
var buf bytes.Buffer
err = png.Encode(&buf, image)
return buf.Bytes(), err
}

func (m users) positive() users {
var m1 []*userInfo
for _, i2 := range m {
Expand Down

0 comments on commit c6dcc9b

Please sign in to comment.