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

qqwife新增好感度列表功能 #504

Merged
merged 5 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,8 @@ NeteaseCloudMusicApi项目地址:https://binaryify.github.io/NeteaseCloudMusicAp

- [x] 群老婆列表

- [x] 好感度列表

- [x] 重置花名册

</details>
Expand Down
71 changes: 71 additions & 0 deletions plugin/qqwife/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 40 additions & 0 deletions plugin/qqwife/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package qqwife

import (
"errors"
"sort"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -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()
Expand Down