feat: 添加时间间隔信息
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package scoresaber
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"git.lxtend.com/qqbot/handler"
|
||||
@@ -17,11 +18,28 @@ func init() {
|
||||
}
|
||||
|
||||
func getMySS(msg model.Message) (reply model.Reply) {
|
||||
resultStr := ""
|
||||
var err error
|
||||
for ; err != nil; resultStr, err = scoresaber.SSQuery.GetScore(strconv.Itoa(int(msg.UserId))) {
|
||||
var (
|
||||
resultStr string
|
||||
err error
|
||||
maxRetries = 3 // 最大重试次数
|
||||
attempts = 0
|
||||
)
|
||||
|
||||
userIdStr := strconv.Itoa(int(msg.UserId))
|
||||
for attempts < maxRetries {
|
||||
resultStr, err = scoresaber.SSQuery.GetScore(userIdStr)
|
||||
if err == nil {
|
||||
break // 成功时退出循环
|
||||
}
|
||||
attempts++
|
||||
log.Printf("获取分数时出错,第 %d 次重试: %v", attempts, err)
|
||||
}
|
||||
|
||||
// 如果所有尝试都失败,返回适当的错误消息
|
||||
if err != nil {
|
||||
resultStr = "获取您的分数时出现问题,请稍后重试。"
|
||||
}
|
||||
|
||||
return model.Reply{
|
||||
ReplyMsg: resultStr,
|
||||
ReferOriginMsg: true,
|
||||
|
||||
Reference in New Issue
Block a user