feat: 添加时间间隔信息
This commit is contained in:
parent
769308389a
commit
115d83ff28
@ -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,
|
||||
|
@ -138,22 +138,43 @@ type RecordDataLite struct {
|
||||
}
|
||||
|
||||
func (r RecordDataLite) ToString() string {
|
||||
formatedStrRanked := "%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrUnranked := "%s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
formatedStrWithoutDevice := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrWithoutDeviceAndRank := "%s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,准度为 %s。"
|
||||
formatedStrRanked := "%s,%s 使用 %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrUnranked := "%s, %s 使用 %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
formatedStrWithoutDevice := "%s, %s 在 %s 的 %s 难度(%.1f星级)中获得了 %d 分,pp 为 %.2f,准度为 %s。"
|
||||
formatedStrWithoutDeviceAndRank := "%s, %s 在 %s 的 %s 难度中获得了 %d 分,准度为 %s。"
|
||||
hardStr := strings.Split(r.DifficultyRaw, "_")[1]
|
||||
layout := "2006-01-02 15:04:05.999999999-07:00"
|
||||
parsedTime, _ := time.Parse(layout, r.GeneratedTime)
|
||||
duration := time.Since(parsedTime)
|
||||
timeStr := timeConvert(duration)
|
||||
if r.Stars == 0 && r.DeviceHmd != "" {
|
||||
return fmt.Sprintf(formatedStrUnranked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrUnranked, timeStr, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else if r.Stars != 0 && r.DeviceHmd != "" {
|
||||
return fmt.Sprintf(formatedStrRanked, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrRanked, timeStr, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else if r.Stars != 0 && r.DeviceHmd == "" {
|
||||
return fmt.Sprintf(formatedStrWithoutDevice, r.Name, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrWithoutDevice, timeStr, r.Name, r.SongName, hardStr, r.Stars, r.Score, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
} else {
|
||||
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, r.Name, r.SongName, hardStr, r.Stars, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, timeStr, r.Name, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
|
||||
}
|
||||
}
|
||||
|
||||
func timeConvert(duration time.Duration) string {
|
||||
var result string
|
||||
if duration.Hours() >= 24 {
|
||||
days := int(duration.Hours() / 24)
|
||||
result = fmt.Sprintf("%d天前", days)
|
||||
} else if duration.Hours() >= 1 {
|
||||
hours := int(duration.Hours())
|
||||
result = fmt.Sprintf("%d小时前", hours)
|
||||
} else if duration.Minutes() >= 1 {
|
||||
minutes := int(duration.Minutes())
|
||||
result = fmt.Sprintf("%d分钟前", minutes)
|
||||
} else {
|
||||
result = "刚刚"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
//用户信息
|
||||
|
||||
// ScoreStats 存储分数统计信息
|
||||
|
Loading…
x
Reference in New Issue
Block a user