From 54110f7a62da351f1ec57c6212a138c67c38c0e2 Mon Sep 17 00:00:00 2001 From: Jiang-Red <79574799+Jiang-Red@users.noreply.github.com> Date: Sun, 13 Oct 2024 10:02:52 +0000 Subject: [PATCH 1/2] feat(chatcount): rank use image --- go.mod | 2 +- go.sum | 4 +-- gomod2nix.toml | 4 +-- plugin/chatcount/chatcount.go | 68 +++++++++++++++++++++++++++-------- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 6282d6a68f..e45574a18c 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( 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 - github.com/FloatTech/zbputils v1.7.2-0.20240822065525-5ea6811ed91c + github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8 github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 github.com/antchfx/htmlquery v1.3.3 diff --git a/go.sum b/go.sum index de35f13c61..c1d648a653 100644 --- a/go.sum +++ b/go.sum @@ -17,8 +17,8 @@ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562 h1:snfw7FNFym1eNnLrQ github.com/FloatTech/ttl v0.0.0-20240716161252-965925764562/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb h1:sGqwCiMDyUD/znWEVVRVxbd6Kg1KLgGnnIuq5bCUWaQ= github.com/FloatTech/zbpctrl v1.6.2-0.20240904160347-1317e11a15bb/go.mod h1:I+MetM++1sJhNPg3zww1aw04BicYsNohvHC4Jh52XSo= -github.com/FloatTech/zbputils v1.7.2-0.20240822065525-5ea6811ed91c h1:hFiqx4uk6+lc2zHAaQ3JkkI2KH59c6O4yHKWKXFzxLs= -github.com/FloatTech/zbputils v1.7.2-0.20240822065525-5ea6811ed91c/go.mod h1:MwTFLPhlP0qMMLcq4x90oiu1IVE1T5dN0ZsxyTGSf6k= +github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8 h1:XlOrX7WJqIQVBziB+ZXXzp/OG0YQICO5IC6T9s4iohE= +github.com/FloatTech/zbputils v1.7.2-0.20240911161040-1d89a7b10ff8/go.mod h1:2ZS6vZHn/imRIOhlDytd/FPVdBIY5KYdTPTIwBJU9Js= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7 h1:S/ferNiehVjNaBMNNBxUjLtVmP/YWD6Yh79RfPv4ehU= github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w= diff --git a/gomod2nix.toml b/gomod2nix.toml index 9163867b7e..c8490b22f1 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -29,8 +29,8 @@ schema = 3 version = "v1.6.2-0.20240904160347-1317e11a15bb" hash = "sha256-x0ZR2bnkboEIjjRFMtMAN0T34BP9BPs7r3AwT3BCyzo=" [mod."github.com/FloatTech/zbputils"] - version = "v1.7.2-0.20240822065525-5ea6811ed91c" - hash = "sha256-ouAExps1iPCcD1AmOxyhRXMBGHBDXvUGkplcnQCf3Bg=" + version = "v1.7.2-0.20240911161040-1d89a7b10ff8" + hash = "sha256-3j7LE5Uqx5kPmi6c+WJEBFtLK0JGU4UGX7RpVuAjmf8=" [mod."github.com/RomiChan/syncx"] version = "v0.0.0-20240418144900-b7402ffdebc7" hash = "sha256-L1j1vgiwqXpF9pjMoRRlrQUHzoULisw/01plaEAwxs4=" diff --git a/plugin/chatcount/chatcount.go b/plugin/chatcount/chatcount.go index 6055c14f98..c490716546 100644 --- a/plugin/chatcount/chatcount.go +++ b/plugin/chatcount/chatcount.go @@ -3,15 +3,21 @@ package chatcount import ( "fmt" + "image" + "net/http" "strconv" - "strings" + "sync" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" + "github.com/FloatTech/floatbox/file" + "github.com/FloatTech/imgfactory" + "github.com/FloatTech/rendercard" ctrl "github.com/FloatTech/zbpctrl" "github.com/FloatTech/zbputils/control" "github.com/FloatTech/zbputils/ctxext" + "github.com/FloatTech/zbputils/img/text" ) const ( @@ -43,22 +49,54 @@ func init() { }) engine.OnFullMatch("查看水群排名", zero.OnlyGroup).Limit(ctxext.LimitByGroup).SetBlock(true). Handle(func(ctx *zero.Ctx) { - text := strings.Builder{} - text.WriteString("今日水群排行榜:\n") chatTimeList := ctdb.getChatRank(ctx.Event.GroupID) + if len(chatTimeList) == 0 { + ctx.SendChain(message.Text("ERROR: 没有水群数据")) + return + } + rankinfo := make([]*rendercard.RankInfo, len(chatTimeList)) + + wg := &sync.WaitGroup{} + wg.Add(len(chatTimeList)) for i := 0; i < len(chatTimeList) && i < rankSize; i++ { - text.WriteString("第") - text.WriteString(strconv.Itoa(i + 1)) - text.WriteString("名:") - text.WriteString(ctx.CardOrNickName(chatTimeList[i].UserID)) - text.WriteString(" - ") - text.WriteString(strconv.FormatInt(chatTimeList[i].TodayMessage, 10)) - text.WriteString("条,共") - text.WriteString(strconv.FormatInt(chatTimeList[i].TodayTime/60, 10)) - text.WriteString("分") - text.WriteString(strconv.FormatInt(chatTimeList[i].TodayTime%60, 10)) - text.WriteString("秒\n") + go func(i int) { + defer wg.Done() + resp, err := http.Get("https://q4.qlogo.cn/g?b=qq&nk=" + strconv.FormatInt(chatTimeList[i].UserID, 10) + "&s=100") + if err != nil { + return + } + defer resp.Body.Close() + img, _, err := image.Decode(resp.Body) + if err != nil { + return + } + rankinfo[i] = &rendercard.RankInfo{ + TopLeftText: ctx.CardOrNickName(chatTimeList[i].UserID), + BottomLeftText: "消息数: " + strconv.FormatInt(chatTimeList[i].TodayMessage, 10) + " 条", + RightText: strconv.FormatInt(chatTimeList[i].TodayTime/60, 10) + "分" + strconv.FormatInt(chatTimeList[i].TodayTime%60, 10) + "秒", + Avatar: img, + } + }(i) + } + wg.Wait() + fontbyte, err := file.GetLazyData(text.GlowSansFontFile, control.Md5File, true) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return + } + img, err := rendercard.DrawRankingCard(fontbyte, "今日水群排行榜", rankinfo) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return } - ctx.SendChain(message.Text(text.String())) + sendimg, err := imgfactory.ToBytes(img) + if err != nil { + ctx.SendChain(message.Text("ERROR: ", err)) + return + } + if id := ctx.SendChain(message.ImageBytes(sendimg)); id.ID() == 0 { + ctx.SendChain(message.Text("ERROR: 可能被风控了")) + } + }) } From cf0ac6d5fa9a4d90b4b5b95b65fc23edb9d9ac3f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 13 Oct 2024 18:05:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore(lint):=20=E6=94=B9=E8=BF=9B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=B7=E5=BC=8F=20(#31)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- plugin/chatcount/chatcount.go | 1 - 1 file changed, 1 deletion(-) diff --git a/plugin/chatcount/chatcount.go b/plugin/chatcount/chatcount.go index c490716546..a4e1bb41a8 100644 --- a/plugin/chatcount/chatcount.go +++ b/plugin/chatcount/chatcount.go @@ -97,6 +97,5 @@ func init() { if id := ctx.SendChain(message.ImageBytes(sendimg)); id.ID() == 0 { ctx.SendChain(message.Text("ERROR: 可能被风控了")) } - }) }