refactor: 重构ss输出,重构url解析

This commit is contained in:
lixiangwuxian
2024-10-17 01:51:00 +08:00
parent 48891fbd0a
commit d4b8e7c11f
9 changed files with 241 additions and 78 deletions

View File

@@ -16,31 +16,34 @@ func (c Command) ToString() string {
if c.CommandName != "score" {
return ""
}
strWithRank := "玩家 %s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中得了 %d 分,排名第 %dpp 为 %.2f。"
strWithoutRank := "玩家 %s 使用 %s 在 %s 的 %s 难度中得了 %d 分,排名第 %d。"
strWithOutDevice := "玩家 %s 在 %s 的 %s 难度(%.1f🌟)中得了 %d 分,排名第 %dpp 为 %.2f。"
strWithOutDeviceAndRank := "玩家 %s 在 %s 的 %s 难度(%.1f🌟)中得了 %d 分。"
strWithRank := "%s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中得了排名第%d的成绩pp 为%.2f。"
strWithoutRank := "%s 使用 %s 在 %s 的 %s 难度中得了排名第%d的成绩。"
strWithOutDevice := "%s 在 %s 的 %s 难度(%.1f🌟)中得了排名第%d的成绩pp 为%.2f。"
strWithOutDeviceAndRank := "%s 在 %s 的 %s 难度(%.1f🌟)中得了排名第%d的成绩。"
hardStr := strings.Split(c.CommandData.Leaderboard.Difficulty.DifficultyRaw, "_")[1]
if c.CommandData.Leaderboard.Ranked && c.CommandData.Score.DeviceHmd != nil {
return fmt.Sprintf(strWithRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, *c.CommandData.Score.DeviceHmd, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.ModifiedScore, c.CommandData.Score.Rank, c.CommandData.Score.Pp)
return fmt.Sprintf(strWithRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, *c.CommandData.Score.DeviceHmd, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.Rank, c.CommandData.Score.Pp)
} else if !c.CommandData.Leaderboard.Ranked && c.CommandData.Score.DeviceHmd != nil {
return fmt.Sprintf(strWithoutRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, *c.CommandData.Score.DeviceHmd, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Score.ModifiedScore, c.CommandData.Score.Rank)
return fmt.Sprintf(strWithoutRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, *c.CommandData.Score.DeviceHmd, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Score.Rank)
} else if c.CommandData.Leaderboard.Ranked && c.CommandData.Score.DeviceHmd == nil {
return fmt.Sprintf(strWithOutDevice, c.CommandData.Score.LeaderboardPlayerInfo.Name, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.ModifiedScore, c.CommandData.Score.Rank, c.CommandData.Score.Pp)
return fmt.Sprintf(strWithOutDevice, c.CommandData.Score.LeaderboardPlayerInfo.Name, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.Rank, c.CommandData.Score.Pp)
} else {
return fmt.Sprintf(strWithOutDeviceAndRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.ModifiedScore)
return fmt.Sprintf(strWithOutDeviceAndRank, c.CommandData.Score.LeaderboardPlayerInfo.Name, c.CommandData.Leaderboard.SongName, hardStr, c.CommandData.Leaderboard.Stars, c.CommandData.Score.Rank)
}
}
// type Badge struct {
// Description string `json:"description"`
// Image string `json:"image"`
// }
// LeaderboardPlayerInfo 表示玩家的信息
type LeaderboardPlayerInfo struct {
ID string `json:"id"`
Name string `json:"name"`
ProfilePicture string `json:"profilePicture"`
Country string `json:"country"`
Permissions int `json:"permissions"`
Badges *string `json:"badges"`
Role *string `json:"role"`
ID string `json:"id"`
Name string `json:"name"`
ProfilePicture string `json:"profilePicture"`
Country string `json:"country"`
Permissions int `json:"permissions"`
}
// Score 表示分数的信息
@@ -125,6 +128,7 @@ type RecordDataLite struct {
Weight float64 `json:"weight" db:"weight"`
Modifiers string `json:"modifiers" db:"modifiers"`
Multiplier float64 `json:"multiplier" db:"multiplier"`
Rank int `json:"rank" db:"rank"`
BadCuts int `json:"badCuts" db:"bad_cuts"`
MissedNotes int `json:"missedNotes" db:"missed_notes"`
MaxCombo int `json:"maxCombo" db:"max_combo"`
@@ -138,23 +142,23 @@ type RecordDataLite struct {
}
func (r RecordDataLite) ToString() string {
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。"
formatedStrRanked := "%s%s 使用 %s 在 %s 的 %s 难度(%.1f🌟)中打到了全球排名第%dpp 为 %.2f,准度为 %s。"
formatedStrUnranked := "%s, %s 使用 %s 在 %s 的 %s 难度中打到了全球排名第%d,准度为 %s。"
formatedStrWithoutDevice := "%s, %s 在 %s 的 %s 难度(%.1f🌟)中打到了全球排名第%dpp 为 %.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, timeStr, 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.Rank, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else if r.Stars != 0 && r.DeviceHmd != "" {
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))
return fmt.Sprintf(formatedStrRanked, timeStr, r.Name, r.DeviceHmd, r.SongName, hardStr, r.Stars, r.Rank, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else if r.Stars != 0 && r.DeviceHmd == "" {
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))
return fmt.Sprintf(formatedStrWithoutDevice, timeStr, r.Name, r.SongName, hardStr, r.Stars, r.Rank, r.PP, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
} else {
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, timeStr, r.Name, r.SongName, hardStr, r.Score, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
return fmt.Sprintf(formatedStrWithoutDeviceAndRank, timeStr, r.Name, r.SongName, hardStr, r.Rank, fmt.Sprintf("%.2f%%", float64(r.Score)/float64(r.MaxScore)*100))
}
}
@@ -189,22 +193,22 @@ type ScoreStats struct {
// PlayerData 存储玩家的完整信息
type PlayerData struct {
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
ProfilePicture string `json:"profilePicture" db:"profile_picture"`
Bio *string `json:"bio" db:"bio"`
Country string `json:"country" db:"country"`
PP float64 `json:"pp" db:"pp"`
Rank int `json:"rank" db:"rank"`
CountryRank int `json:"countryRank" db:"country_rank"`
Role *string `json:"role" db:"role"`
Badges []string `json:"badges" db:"badges"`
Histories string `json:"histories" db:"histories"`
Permissions int `json:"permissions" db:"permissions"`
Banned bool `json:"banned" db:"banned"`
Inactive bool `json:"inactive" db:"inactive"`
ScoreStats ScoreStats `json:"scoreStats" db:"score_stats"`
FirstSeen time.Time `json:"firstSeen" db:"first_seen"`
ID string `json:"id" db:"id"`
Name string `json:"name" db:"name"`
ProfilePicture string `json:"profilePicture" db:"profile_picture"`
Bio *string `json:"bio" db:"bio"`
Country string `json:"country" db:"country"`
PP float64 `json:"pp" db:"pp"`
Rank int `json:"rank" db:"rank"`
CountryRank int `json:"countryRank" db:"country_rank"`
Role *string `json:"role" db:"role"`
// Badges []string `json:"badges" db:"badges"`
Histories string `json:"histories" db:"histories"`
Permissions int `json:"permissions" db:"permissions"`
Banned bool `json:"banned" db:"banned"`
Inactive bool `json:"inactive" db:"inactive"`
ScoreStats ScoreStats `json:"scoreStats" db:"score_stats"`
FirstSeen time.Time `json:"firstSeen" db:"first_seen"`
}
type PlayerDataLite struct {
@@ -230,13 +234,11 @@ func (p PlayerData) ToString() string {
"PP %.1f\n" +
"全球排名 %d\n" +
"区域排名 %d\n" +
"总分 %d\n" +
"Ranked谱面总分 %d\n" +
"平均Ranked谱面准确率 %.2f\n" +
"Ranked谱面均准 %.2f%%\n" +
"总游玩次数 %d\n" +
"Ranked谱面游玩次数 %d\n" +
"回放被观看次数 %d"
return fmt.Sprintf(formatedStr, p.Name, p.Country, p.PP, p.Rank, p.CountryRank, p.ScoreStats.TotalScore, p.ScoreStats.TotalRankedScore, p.ScoreStats.AverageRankedAccuracy, p.ScoreStats.TotalPlayCount, p.ScoreStats.RankedPlayCount, p.ScoreStats.ReplaysWatched)
return fmt.Sprintf(formatedStr, p.Name, p.Country, p.PP, p.Rank, p.CountryRank, p.ScoreStats.AverageRankedAccuracy, p.ScoreStats.TotalPlayCount, p.ScoreStats.RankedPlayCount, p.ScoreStats.ReplaysWatched)
}
func (p PlayerDataLite) ToString() string {
@@ -245,13 +247,11 @@ func (p PlayerDataLite) ToString() string {
"PP %.1f\n" +
"全球排名 %d\n" +
"区域排名 %d\n" +
"总分 %d\n" +
"Ranked谱面总分 %d\n" +
"平均Ranked谱面准确率 %.2f\n" +
"Ranked谱面均准 %.2f%%\n" +
"总游玩次数 %d\n" +
"Ranked谱面游玩次数 %d\n" +
"回放被观看次数 %d"
return fmt.Sprintf(formatedStr, p.Name, p.Country, p.PP, p.Rank, p.CountryRank, p.TotalScore, p.TotalRankedScore, p.AverageRankedAccuracy, p.TotalPlayCount, p.RankedPlayCount, p.ReplaysWatched)
return fmt.Sprintf(formatedStr, p.Name, p.Country, p.PP, p.Rank, p.CountryRank, p.AverageRankedAccuracy, p.TotalPlayCount, p.RankedPlayCount, p.ReplaysWatched)
}
func (p PlayerData) LastDiffToString(lastDayQueryData PlayerDataLite) string {
@@ -260,11 +260,18 @@ func (p PlayerData) LastDiffToString(lastDayQueryData PlayerDataLite) string {
"PP %.1f(%+.1f)\n" +
"全球排名 %d(%+d)\n" +
"区域排名 %d(%+d)\n" +
"总分 %d(%+d)\n" +
"Ranked谱面总分 %d(%+d)\n" +
"平均Ranked谱面准确率 %.2f(%+.2f)\n" +
"Ranked谱面均准 %.2f%%(%+.2f%%)\n" +
"总游玩次数 %d(%+d)\n" +
"Ranked谱面游玩次数 %d(%+d)\n" +
"回放被观看次数 %d"
return fmt.Sprintf(formatedStr, p.Name, p.Country, p.PP, p.PP-lastDayQueryData.PP, p.Rank, lastDayQueryData.Rank-p.Rank, p.CountryRank, lastDayQueryData.CountryRank-p.CountryRank, p.ScoreStats.TotalScore, p.ScoreStats.TotalScore-lastDayQueryData.TotalScore, p.ScoreStats.TotalRankedScore, p.ScoreStats.TotalRankedScore-lastDayQueryData.TotalRankedScore, p.ScoreStats.AverageRankedAccuracy, p.ScoreStats.AverageRankedAccuracy-lastDayQueryData.AverageRankedAccuracy, p.ScoreStats.TotalPlayCount, p.ScoreStats.TotalPlayCount-lastDayQueryData.TotalPlayCount, p.ScoreStats.RankedPlayCount, p.ScoreStats.RankedPlayCount-lastDayQueryData.RankedPlayCount, p.ScoreStats.ReplaysWatched)
return fmt.Sprintf(formatedStr,
p.Name,
p.Country,
p.PP, p.PP-lastDayQueryData.PP,
p.Rank, lastDayQueryData.Rank-p.Rank,
p.CountryRank, lastDayQueryData.CountryRank-p.CountryRank,
p.ScoreStats.AverageRankedAccuracy, p.ScoreStats.AverageRankedAccuracy-lastDayQueryData.AverageRankedAccuracy,
p.ScoreStats.TotalPlayCount, p.ScoreStats.TotalPlayCount-lastDayQueryData.TotalPlayCount,
p.ScoreStats.RankedPlayCount, p.ScoreStats.RankedPlayCount-lastDayQueryData.RankedPlayCount,
p.ScoreStats.ReplaysWatched)
}