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 13, 2024
1 parent 647366c commit 1edcd6b
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 237 deletions.
48 changes: 48 additions & 0 deletions plugin/niuniu/draw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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, t bool) (img image.Image, err error) {
var (
title string
s string
)
title = "牛牛深度排行"
s = "牛牛深度"
if t {
title = "牛牛长度排行"
s = "牛牛长度"
}
var ri []*rendercard.RankInfo

Check failure on line 29 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.RankInfo

Check failure on line 29 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.RankInfo

Check failure on line 29 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: rendercard.RankInfo

Check failure on line 29 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: rendercard.RankInfo
for _, 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)
if err != nil {
return nil, err
}
ri = append(ri, &rendercard.RankInfo{

Check failure on line 39 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.RankInfo

Check failure on line 39 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.RankInfo

Check failure on line 39 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: rendercard.RankInfo

Check failure on line 39 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: 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(font, title, ri)

Check failure on line 46 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.DrawRankingCard (typecheck)

Check failure on line 46 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / lint

undefined: rendercard.DrawRankingCard) (typecheck)

Check failure on line 46 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, 386)

undefined: rendercard.DrawRankingCard

Check failure on line 46 in plugin/niuniu/draw.go

View workflow job for this annotation

GitHub Actions / Build binary CI (linux, amd64)

undefined: rendercard.DrawRankingCard
return
}
55 changes: 39 additions & 16 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
package niuniu

import (
"bytes"
"fmt"
"image/png"
"math/rand"
"strconv"
"strings"
Expand Down Expand Up @@ -208,16 +210,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, 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()))

})
en.OnFullMatch("牛子深度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
Expand All @@ -231,16 +244,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(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, false)
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("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand Down
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
Loading

0 comments on commit 1edcd6b

Please sign in to comment.