refactor: 替换 getMyBL 函数为 getMyBLPic,仅生成图片

This commit is contained in:
lixiangwuxian 2025-05-10 14:59:24 +08:00
parent f8a5287b17
commit 9e2b6b3162

View File

@ -18,9 +18,9 @@ import (
)
func init() {
handler.RegisterHandler("查bl", getMyBL, constants.LEVEL_USER)
handler.RegisterHandler("查bl", getMyBLPic, constants.LEVEL_USER)
handler.RegisterHelpInform("查bl", "beatleader", "查bl 查看您的最新分数")
handler.RegisterHandler("查bl图", getMyBLPic, constants.LEVEL_USER)
// 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账号")
@ -167,44 +167,6 @@ func blPlus(msg model.Message) (reply *model.Reply) {
}
}
func getMyBL(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.LastDiffToString(*lastData)
} else {
resultStr = data.LastDiffToString(*data)
}
return &model.Reply{
ReplyMsg: resultStr,
ReferOriginMsg: true,
FromMsg: msg,
}
}
func getMyBLPic(msg model.Message) (reply *model.Reply) {
var (
resultStr string