mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
qqwife新增好感度列表功能 (#504)
This commit is contained in:
parent
fb4259b696
commit
8eef7718ee
@ -1065,6 +1065,8 @@ NeteaseCloudMusicApi项目地址:https://binaryify.github.io/NeteaseCloudMusicAp
|
||||
|
||||
- [x] 群老婆列表
|
||||
|
||||
- [x] 好感度列表
|
||||
|
||||
- [x] 重置花名册
|
||||
|
||||
</details>
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user