feat: 添加查bl图命令以获取最新分数截图,并优化头像处理逻辑,使用新的图片缩放方法

This commit is contained in:
lixiangwuxian
2025-05-10 14:33:53 +08:00
parent aa9994de17
commit 74b92f675b
7 changed files with 217 additions and 14 deletions

View File

@@ -20,6 +20,8 @@ import (
func init() {
handler.RegisterHandler("查bl", getMyBL, constants.LEVEL_USER)
handler.RegisterHelpInform("查bl", "beatleader", "查bl 查看您的最新分数")
handler.RegisterHandler("查bl图", getMyBLPic, constants.LEVEL_USER)
// handler.RegisterHelpInform("查bl图", "beatleader", "查bl图 查看您的最新分数截图")
handler.RegisterHandler("绑定bl", bindBL, constants.LEVEL_USER)
handler.RegisterHelpInform("绑定bl", "beatleader", "绑定bl 绑定您的beatleader账号")
handler.RegisterHandler("解绑bl", unbindBL, constants.LEVEL_USER)
@@ -189,6 +191,7 @@ func getMyBL(msg model.Message) (reply *model.Reply) {
if err != nil {
resultStr = "获取您的分数时出现问题,请稍后重试。"
}
if lastData != nil {
resultStr = data.LastDiffToString(*lastData)
} else {
@@ -201,6 +204,52 @@ func getMyBL(msg model.Message) (reply *model.Reply) {
FromMsg: msg,
}
}
func getMyBLPic(msg model.Message) (reply *model.Reply) {
var (
resultStr string
err error
maxRetries = 3 // 最大重试次数
attempts = 0
)
userIdStr := strconv.Itoa(int(msg.UserId))
var data *beatleader.PlayerDataLite
var lastData *beatleader.PlayerDataLite
for attempts < maxRetries {
data, lastData, err = beatleader.BLQuery.GetScore(userIdStr)
if err == nil {
break // 成功时退出循环
}
attempts++
log.Printf("获取分数时出错,第 %d 次重试: %v", attempts, err)
}
// 如果所有尝试都失败,返回适当的错误消息
if err != nil {
resultStr = "获取您的分数时出现问题,请稍后重试。"
}
if lastData != nil {
resultStr = data.LastDiffToImage(*lastData)
} else {
resultStr = data.LastDiffToImage(*data)
}
imageMsg := message.ImageMessage{
Type: "image",
Data: message.ImageMessageData{
File: resultStr,
},
}
return &model.Reply{
ReplyMsg: imageMsg.ToCQString(),
ReferOriginMsg: true,
FromMsg: msg,
}
}
func bindBL(msg model.Message) (reply *model.Reply) {
if len(msg.RawMsg) <= len("绑定bl ") {
return &model.Reply{
@@ -264,7 +313,7 @@ func getMyRecentScore(msg model.Message) (reply *model.Reply) {
log.Printf("下载图片失败: %v", err)
return
}
newPath, err := util.ResizeImageByMaxHeight(filePath, 20)
newPath, err := util.ResizeImageByMaxHeight2File(filePath, 20)
if err != nil {
log.Printf("缩放图片失败: %v", err)
}