refactor: 优化 getMySSPic 函数,支持从消息中提取用户ID并处理头像为 nil 的情况,同时调整数据获取逻辑以提升代码灵活性

This commit is contained in:
lixiangwuxian
2025-05-11 02:12:13 +08:00
parent f20edf3e78
commit 22f09b7097
7 changed files with 301 additions and 177 deletions

View File

@@ -30,9 +30,9 @@ func init() {
handler.RegisterHelpInform("bl+n", "beatleader", "查看您需要打多少pp才能达到当前区服的第N名")
handler.RegisterFrontMatchHandler("bl-", blPlus, constants.LEVEL_USER)
handler.RegisterHelpInform("bl-n", "beatleader", "查看落后您N名的玩家需要打多少pp才会超过您")
// handler.RegisterHandler("截bl", screenShotBL, constants.LEVEL_USER)
// handler.RegisterHandler("jbl", screenShotBL, constants.LEVEL_USER)
// handler.RegisterHelpInform("截bl", "beatleader", "截bl 截bl 截bl主页截图")
handler.RegisterHandler("截bl", screenShotBL, constants.LEVEL_USER)
handler.RegisterHandler("jbl", screenShotBL, constants.LEVEL_USER)
handler.RegisterHelpInform("截bl", "beatleader", "截bl 截bl 截bl主页截图")
}
func blPlus(msg model.Message) (reply *model.Reply) {
@@ -175,15 +175,21 @@ func getMyBLPic(msg model.Message) (reply *model.Reply) {
tokens := util.SplitN(msg.RawMsg, 2)
var userIdStr string
var noUpdate bool = false
if len(tokens) == 2 {
userIdStr = tokens[1]
} else {
userIdStr = strconv.Itoa(int(msg.UserId))
noUpdate = true
}
var data *beatleader.PlayerDataLite
var lastData *beatleader.PlayerDataLite
for attempts < maxRetries {
data, lastData, err = beatleader.BLQuery.GetScore(userIdStr)
if noUpdate {
data, err = beatleader.BLQuery.GetScoreWithoutUpdate(userIdStr)
} else {
data, lastData, err = beatleader.BLQuery.GetScore(userIdStr)
}
if err == nil {
break // 成功时退出循环
}
@@ -193,7 +199,11 @@ func getMyBLPic(msg model.Message) (reply *model.Reply) {
// 如果所有尝试都失败,返回适当的错误消息
if err != nil {
resultStr = "获取您的分数时出现问题,请稍后重试。"
return &model.Reply{
ReplyMsg: "获取您的分数时出现问题,请稍后重试。" + err.Error(),
ReferOriginMsg: true,
FromMsg: msg,
}
}
if lastData != nil {