feat: add help inform messages for bot commands and improve error handling in player data fetching

This commit is contained in:
lixiangwuxian 2024-12-28 22:32:05 +08:00
parent ff8d077f1c
commit a1fcfe4366
3 changed files with 61 additions and 52 deletions

View File

@ -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 {

View File

@ -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{

View File

@ -152,7 +152,7 @@ type Player struct {
Rank int `json:"rank"`
CountryRank int `json:"countryRank"`
Role string `json:"role"`
Socials *string `json:"socials"`
// Socials *string `json:"socials"`
ContextExtensions *string `json:"contextExtensions"`
}
@ -269,7 +269,7 @@ type PlayerData struct {
Rank int `json:"rank"`
CountryRank int `json:"countryRank"`
Role string `json:"role"`
Socials []string `json:"socials"`
// Socials []string `json:"socials"`
ContextExtensions *string `json:"contextExtensions"`
PatreonFeatures *string `json:"patreonFeatures"`
ProfileSettings ProfileSettings `json:"profileSettings"`