From 8eef7718ee9175131e944afd9b489e278aabab79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E6=9F=B3=E7=85=9C?= <101934327+fangliuyu@users.noreply.github.com> Date: Wed, 23 Nov 2022 16:39:32 +0800 Subject: [PATCH] =?UTF-8?q?qqwife=E6=96=B0=E5=A2=9E=E5=A5=BD=E6=84=9F?= =?UTF-8?q?=E5=BA=A6=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD=20(#504)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ plugin/qqwife/command.go | 71 +++++++++++++++++++++++++++++++++++++++ plugin/qqwife/function.go | 40 ++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/README.md b/README.md index b98a2b41ba..4d1afc6988 100644 --- a/README.md +++ b/README.md @@ -1065,6 +1065,8 @@ NeteaseCloudMusicApi项目地址:https://binaryify.github.io/NeteaseCloudMusicAp - [x] 群老婆列表 + - [x] 好感度列表 + - [x] 重置花名册 diff --git a/plugin/qqwife/command.go b/plugin/qqwife/command.go index 151f76f595..2d8c174b9b 100644 --- a/plugin/qqwife/command.go +++ b/plugin/qqwife/command.go @@ -648,6 +648,77 @@ func init() { ctx.SendChain(message.ImageBytes(data)) cl() }) + engine.OnFullMatch("好感度列表", zero.OnlyGroup, getdb).SetBlock(true).Limit(ctxext.LimitByUser). + Handle(func(ctx *zero.Ctx) { + uid := ctx.Event.UserID + fianceeInfo, err := 民政局.getGroupFavorability(uid) + if err != nil { + ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) + return + } + /***********设置图片的大小和底色***********/ + number := len(fianceeInfo) + if number > 10 { + number = 10 + } + fontSize := 50.0 + canvas := gg.NewContext(1150, int(170+(50+70)*float64(number))) + canvas.SetRGB(1, 1, 1) // 白色 + canvas.Clear() + /***********下载字体***********/ + _, err = file.GetLazyData(text.BoldFontFile, control.Md5File, true) + if err != nil { + ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) + } + /***********设置字体颜色为黑色***********/ + canvas.SetRGB(0, 0, 0) + /***********设置字体大小,并获取字体高度用来定位***********/ + if err = canvas.LoadFontFace(text.BoldFontFile, fontSize*2); err != nil { + ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) + return + } + sl, h := canvas.MeasureString("你的好感度排行列表") + /***********绘制标题***********/ + canvas.DrawString("你的好感度排行列表", (1100-sl)/2, 100) // 放置在中间位置 + canvas.DrawString("————————————————————", 0, 160) + /***********设置字体大小,并获取字体高度用来定位***********/ + if err = canvas.LoadFontFace(text.BoldFontFile, fontSize); err != nil { + ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) + return + } + i := 0 + for _, info := range fianceeInfo { + if i > 9 { + break + } + if info.Userinfo == "" { + continue + } + fianceID, err := strconv.ParseInt(info.Userinfo, 10, 64) + if err != nil { + ctx.SendChain(message.Text("[qqwife]ERROR: ", err)) + return + } + if fianceID == 0 { + continue + } + userName := ctx.CardOrNickName(fianceID) + canvas.SetRGB255(0, 0, 0) + canvas.DrawString(userName+"("+info.Userinfo+")", 10, float64(180+(50+70)*i)) + canvas.DrawString(strconv.Itoa(info.Favor), 1020, float64(180+60+(50+70)*i)) + canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, 1000, 50) + canvas.SetRGB255(150, 150, 150) + canvas.Fill() + canvas.SetRGB255(0, 0, 0) + canvas.DrawRectangle(10, float64(180+60+(50+70)*i)-h/2, float64(info.Favor)*10, 50) + canvas.SetRGB255(231, 27, 100) + canvas.Fill() + i++ + } + data, cl := writer.ToBytes(canvas.Image()) + ctx.SendChain(message.ImageBytes(data)) + cl() + }) engine.OnRegex(`^重置(所有|本群|/d+)?花名册$`, zero.SuperUserPermission, getdb).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *zero.Ctx) { cmd := "0" diff --git a/plugin/qqwife/function.go b/plugin/qqwife/function.go index 1adce885a3..a35d8a1b74 100644 --- a/plugin/qqwife/function.go +++ b/plugin/qqwife/function.go @@ -2,7 +2,9 @@ package qqwife import ( "errors" + "sort" "strconv" + "strings" "sync" "time" @@ -343,6 +345,44 @@ func (sql *婚姻登记) getFavorability(uid, target int64) (favor int, err erro return } +// 获取好感度数据组 +type favorList []favorability + +func (s favorList) Len() int { + return len(s) +} +func (s favorList) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} +func (s favorList) Less(i, j int) bool { + return s[i].Favor > s[j].Favor +} +func (sql *婚姻登记) getGroupFavorability(uid int64) (list favorList, err error) { + uidStr := strconv.FormatInt(uid, 10) + sql.RLock() + defer sql.RUnlock() + info := favorability{} + err = sql.db.FindFor("favorability", &info, "where Userinfo glob '*"+uidStr+"*'", func() error { + var target string + userList := strings.Split(info.Userinfo, "+") + switch { + case len(userList) == 0: + return errors.New("好感度系统数据存在错误") + case userList[0] == uidStr: + target = userList[1] + default: + target = userList[0] + } + list = append(list, favorability{ + Userinfo: target, + Favor: info.Favor, + }) + return nil + }) + sort.Sort(list) + return +} + // 设置好感度 正增负减 func (sql *婚姻登记) setFavorability(uid, target int64, score int) (favor int, err error) { sql.Lock()