From a1fcfe4366576dacf231a692a648e748e556de6d Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sat, 28 Dec 2024 22:32:05 +0800 Subject: [PATCH] feat: add help inform messages for bot commands and improve error handling in player data fetching --- handler/restart/restart.go | 7 ++- service/beatleader/bind_bl.go | 8 ++- service/beatleader/model.go | 98 +++++++++++++++++------------------ 3 files changed, 61 insertions(+), 52 deletions(-) diff --git a/handler/restart/restart.go b/handler/restart/restart.go index 50b90cc..2587893 100644 --- a/handler/restart/restart.go +++ b/handler/restart/restart.go @@ -17,10 +17,15 @@ var hasVaildBuild = true func init() { handler.RegisterHandler("/重启bot", restart, constants.LEVEL_ADMIN) + handler.RegisterHelpInform("/重启bot", "热更新", "重启bot") handler.RegisterHandler("/构建bot", build, constants.LEVEL_ADMIN) + handler.RegisterHelpInform("/构建bot", "热更新", "构建bot") handler.RegisterHandler("/构建重启", buildAndRestart, constants.LEVEL_ADMIN) - handler.RegisterHandler("/gitpull", pullCode, constants.LEVEL_ADMIN) + handler.RegisterHelpInform("/构建重启", "热更新", "构建并重启") + handler.RegisterHandler("/gitpull", pullCode, constants.LEVEL_USER) + handler.RegisterHelpInform("/gitpull", "热更新", "拉取最新代码") handler.RegisterHandler("/shutdown", shutdown, constants.LEVEL_ADMIN) + handler.RegisterHelpInform("/shutdown", "热更新", "结束程序") } func restart(msg model.Message) model.Reply { diff --git a/service/beatleader/bind_bl.go b/service/beatleader/bind_bl.go index b9ccdb1..4a8da2c 100644 --- a/service/beatleader/bind_bl.go +++ b/service/beatleader/bind_bl.go @@ -138,10 +138,14 @@ func (bl *blQuery) GetScore(qqId string) (reply string, err error) { } // 查询玩家数据 - data, _ := FetchPlayerData(blId) - if data == nil { + data, err := FetchPlayerData(blId) + if data == nil && err == nil { return "查询出错,服务器返回了空数据", errors.New("查询出错,服务器返回了空数据") } + if err != nil { + log.Print(err) + return "查询出错,服务器返回了空数据" + err.Error(), err + } // 构建 PlayerDataLite 结构体 dataLite := PlayerDataLite{ diff --git a/service/beatleader/model.go b/service/beatleader/model.go index 8b1a622..2a7114a 100644 --- a/service/beatleader/model.go +++ b/service/beatleader/model.go @@ -141,18 +141,18 @@ type ModifierValues struct { } type Player struct { - ID string `json:"id"` - Name string `json:"name"` - Platform string `json:"platform"` - Avatar string `json:"avatar"` - Country string `json:"country"` - Alias *string `json:"alias"` - Bot bool `json:"bot"` - Pp float64 `json:"pp"` - Rank int `json:"rank"` - CountryRank int `json:"countryRank"` - Role string `json:"role"` - Socials *string `json:"socials"` + ID string `json:"id"` + Name string `json:"name"` + Platform string `json:"platform"` + Avatar string `json:"avatar"` + Country string `json:"country"` + Alias *string `json:"alias"` + Bot bool `json:"bot"` + Pp float64 `json:"pp"` + Rank int `json:"rank"` + CountryRank int `json:"countryRank"` + Role string `json:"role"` + // Socials *string `json:"socials"` ContextExtensions *string `json:"contextExtensions"` } @@ -238,43 +238,43 @@ func timeConvert(duration time.Duration) string { // ScoreStats 存储分数统计信息 type PlayerData struct { - MapperID int `json:"mapperId"` - Banned bool `json:"banned"` - Inactive bool `json:"inactive"` - BanDescription *string `json:"banDescription"` - ExternalProfileURL string `json:"externalProfileUrl"` - RichBioTimeset int64 `json:"richBioTimeset"` - SpeedrunStart int64 `json:"speedrunStart"` - LinkedIDs LinkedIDs `json:"linkedIds"` - History *string `json:"history"` - Badges []string `json:"badges"` - PinnedScores *string `json:"pinnedScores"` - Changes []Change `json:"changes"` - AccPp float64 `json:"accPp"` - PassPp float64 `json:"passPp"` - TechPp float64 `json:"techPp"` - ScoreStats ScoreStats `json:"scoreStats"` - LastWeekPp float64 `json:"lastWeekPp"` - LastWeekRank int `json:"lastWeekRank"` - LastWeekCountryRank int `json:"lastWeekCountryRank"` - ExtensionID int `json:"extensionId"` - ID string `json:"id"` - Name string `json:"name"` - Platform string `json:"platform"` - Avatar string `json:"avatar"` - Country string `json:"country"` - Alias *string `json:"alias"` - Bot bool `json:"bot"` - Pp float64 `json:"pp"` - Rank int `json:"rank"` - CountryRank int `json:"countryRank"` - Role string `json:"role"` - Socials []string `json:"socials"` - ContextExtensions *string `json:"contextExtensions"` - PatreonFeatures *string `json:"patreonFeatures"` - ProfileSettings ProfileSettings `json:"profileSettings"` - ClanOrder string `json:"clanOrder"` - Clans []string `json:"clans"` + MapperID int `json:"mapperId"` + Banned bool `json:"banned"` + Inactive bool `json:"inactive"` + BanDescription *string `json:"banDescription"` + ExternalProfileURL string `json:"externalProfileUrl"` + RichBioTimeset int64 `json:"richBioTimeset"` + SpeedrunStart int64 `json:"speedrunStart"` + LinkedIDs LinkedIDs `json:"linkedIds"` + History *string `json:"history"` + Badges []string `json:"badges"` + PinnedScores *string `json:"pinnedScores"` + Changes []Change `json:"changes"` + AccPp float64 `json:"accPp"` + PassPp float64 `json:"passPp"` + TechPp float64 `json:"techPp"` + ScoreStats ScoreStats `json:"scoreStats"` + LastWeekPp float64 `json:"lastWeekPp"` + LastWeekRank int `json:"lastWeekRank"` + LastWeekCountryRank int `json:"lastWeekCountryRank"` + ExtensionID int `json:"extensionId"` + ID string `json:"id"` + Name string `json:"name"` + Platform string `json:"platform"` + Avatar string `json:"avatar"` + Country string `json:"country"` + Alias *string `json:"alias"` + Bot bool `json:"bot"` + Pp float64 `json:"pp"` + Rank int `json:"rank"` + CountryRank int `json:"countryRank"` + Role string `json:"role"` + // Socials []string `json:"socials"` + ContextExtensions *string `json:"contextExtensions"` + PatreonFeatures *string `json:"patreonFeatures"` + ProfileSettings ProfileSettings `json:"profileSettings"` + ClanOrder string `json:"clanOrder"` + Clans []string `json:"clans"` } type LinkedIDs struct {