feat: 更新 blPlus 函数以支持获取当前用户所在区对应 + N 位的玩家列表,并修正 PlayerData 中的字段名为大写形式
This commit is contained in:
parent
ec6d65c9b8
commit
a5b6f070b4
@ -25,14 +25,14 @@ func init() {
|
||||
handler.RegisterHelpInform("解绑bl", "beatleader", "解绑bl 解绑您的beatleader账号")
|
||||
handler.RegisterHandler("最新bl", getMyRecentScore, constants.LEVEL_USER)
|
||||
handler.RegisterHelpInform("最新bl", "beatleader", "最新bl 查看您的最新游戏记录")
|
||||
// handler.RegisterHandler("最热bl", getRecentScore, constants.LEVEL_USER)
|
||||
// handler.RegisterHelpInform("最热bl", "beatleader", "最热bl 查看全大陆的最新游戏记录")
|
||||
handler.RegisterHandler("bl+", blPlus, constants.LEVEL_USER)
|
||||
handler.RegisterHelpInform("bl+", "beatleader", "bl+ 查看您需要打多少pp才能达到当前区服的第N名")
|
||||
handler.RegisterHandler("截bl", screenShotBL, constants.LEVEL_USER)
|
||||
handler.RegisterHelpInform("截bl", "beatleader", "截bl 截bl 截bl主页截图")
|
||||
handler.RegisterHandler("jbl", screenShotBL, constants.LEVEL_USER)
|
||||
}
|
||||
|
||||
func blPlus(msg model.Message) (reply model.Reply) {
|
||||
func blPlus(msg model.Message) (reply *model.Reply) {
|
||||
var (
|
||||
resultStr strings.Builder
|
||||
err error
|
||||
@ -43,7 +43,7 @@ func blPlus(msg model.Message) (reply model.Reply) {
|
||||
if len(msg.RawMsg) > len("bl+") {
|
||||
N, err = strconv.Atoi(msg.RawMsg[len("bl+"):])
|
||||
if err != nil || N <= 0 {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "请输入一个正整数",
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@ -53,7 +53,7 @@ func blPlus(msg model.Message) (reply model.Reply) {
|
||||
userIdStr := strconv.Itoa(int(msg.UserId))
|
||||
userBLID, err := scoresaber.GetSSID(userIdStr)
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
@ -69,24 +69,39 @@ func blPlus(msg model.Message) (reply model.Reply) {
|
||||
attempts++
|
||||
}
|
||||
if err != nil {
|
||||
return model.Reply{
|
||||
return &model.Reply{
|
||||
ReplyMsg: "获取您的分数时出现问题,请稍后重试。" + err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
resultStr.WriteString(fmt.Sprintf("您当前的全区排名为:%d\n", userInfo.CountryRank))
|
||||
// 获取当前用户所在区对应+N位的玩家列表
|
||||
// leaderboard, err := beatleader.FetchCountryLeaderboard(userInfo.Country, userInfo.CountryRank-N, userInfo.ID)
|
||||
// if err != nil {
|
||||
// return model.Reply{
|
||||
// ReplyMsg: "获取当前用户所在区对应+N位的玩家列表时出现问题,请稍后重试。" + err.Error(),
|
||||
// ReferOriginMsg: true,
|
||||
// FromMsg: msg,
|
||||
// }
|
||||
// }
|
||||
// resultStr.WriteString(fmt.Sprintf("您只需要再打出%.2fpp就能达到%s区第%d名。", targetPlayer.PP-userInfo.PP, userInfo.Country, targetPlayer.CountryRank))
|
||||
return model.Reply{
|
||||
// 获取当前用户所在区对应 + N位的玩家列表
|
||||
leaderboard, err := beatleader.FetchCountryLeaderboard(userInfo.Country, userInfo.CountryRank-N, userInfo.ID)
|
||||
if err != nil {
|
||||
return &model.Reply{
|
||||
ReplyMsg: "获取当前用户所在区对应+N位的玩家列表时出现问题,请稍后重试。" + err.Error(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
}
|
||||
}
|
||||
if userInfo.CountryRank-N < 0 {
|
||||
resultStr.WriteString(fmt.Sprintf("注意:你最多只需要提升%d名就是%s区Top1了。\n", userInfo.CountryRank-1, userInfo.Country))
|
||||
}
|
||||
//寻找leaderboard中排名为userInfo.CountryRank-N的玩家
|
||||
var targetPlayer beatleader.PlayerDataLite
|
||||
targetRank := userInfo.CountryRank - N
|
||||
if targetRank < 0 {
|
||||
targetRank = 1
|
||||
}
|
||||
for _, player := range leaderboard {
|
||||
if player.CountryRank == targetRank {
|
||||
targetPlayer = player
|
||||
break
|
||||
}
|
||||
}
|
||||
resultStr.WriteString(fmt.Sprintf("您只需要再打出%.2fpp就能达到%s区第%d名。", targetPlayer.PP-userInfo.PP, userInfo.Country, targetPlayer.CountryRank))
|
||||
return &model.Reply{
|
||||
ReplyMsg: resultStr.String(),
|
||||
ReferOriginMsg: true,
|
||||
FromMsg: msg,
|
||||
|
@ -271,7 +271,7 @@ type PlayerData struct {
|
||||
Country string `json:"country"`
|
||||
// Alias *string `json:"alias"`
|
||||
Bot bool `json:"bot"`
|
||||
Pp float64 `json:"pp"`
|
||||
PP float64 `json:"pp"`
|
||||
Rank int `json:"rank"`
|
||||
CountryRank int `json:"countryRank"`
|
||||
Role string `json:"role"`
|
||||
@ -436,7 +436,7 @@ func (p PlayerData) ToString() string {
|
||||
return fmt.Sprintf(formatedStr,
|
||||
p.Name,
|
||||
p.Country,
|
||||
p.Pp,
|
||||
p.PP,
|
||||
p.Rank,
|
||||
p.CountryRank,
|
||||
p.ScoreStats.AverageRankedAccuracy*100,
|
||||
@ -496,7 +496,7 @@ func (p PlayerData) LastDiffToString(lastDayQueryData PlayerDataLite) string {
|
||||
return fmt.Sprintf(formatedStr,
|
||||
p.Name,
|
||||
p.Country,
|
||||
p.Pp, p.Pp-lastDayQueryData.PP,
|
||||
p.PP, p.PP-lastDayQueryData.PP,
|
||||
p.Rank, lastDayQueryData.Rank-p.Rank,
|
||||
p.CountryRank, lastDayQueryData.CountryRank-p.CountryRank,
|
||||
p.ScoreStats.AverageRankedAccuracy*100, (p.ScoreStats.AverageRankedAccuracy-lastDayQueryData.AverageRankedAccuracy)*100,
|
||||
|
@ -68,11 +68,14 @@ func FetchPlayerData(blID string) (*PlayerData, error) {
|
||||
return &playerData, nil
|
||||
}
|
||||
|
||||
func FetchCountryLeaderboard(country string, aimRank int, userId string) (*PlayerDataLite, error) {
|
||||
url := fmt.Sprintf("https://api.beatleader.com/players?leaderboardContext=general&page=1&count=50&sortBy=pp&mapsType=ranked&ppType=general&order=desc")
|
||||
func FetchCountryLeaderboard(country string, offset int, userId string) ([]PlayerDataLite, error) {
|
||||
url := fmt.Sprintf("https://api.beatleader.com/players?leaderboardContext=general&page=%d&count=50&sortBy=pp&mapsType=ranked&ppType=general&order=desc&countries=%s", offset/50+1, country)
|
||||
|
||||
// 创建请求
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置请求头
|
||||
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0")
|
||||
@ -114,11 +117,14 @@ func FetchCountryLeaderboard(country string, aimRank int, userId string) (*Playe
|
||||
}
|
||||
|
||||
// 解析响应体
|
||||
var playerDataLite PlayerDataLite
|
||||
err = json.NewDecoder(reader).Decode(&playerDataLite)
|
||||
type Response struct {
|
||||
Data []PlayerDataLite `json:"data"`
|
||||
}
|
||||
var response Response
|
||||
err = json.NewDecoder(reader).Decode(&response)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &playerDataLite, nil
|
||||
return response.Data, nil
|
||||
}
|
||||
|
@ -143,8 +143,7 @@ func FetchCountryLeaderboard(country string, offset int, ssID string) (Leaderboa
|
||||
if offset < 1 {
|
||||
offset = 1
|
||||
}
|
||||
page := (offset-1)/50 + 1
|
||||
url := fmt.Sprintf("https://scoresaber.com/api/players?countries=%s&page=%d", country, page)
|
||||
url := fmt.Sprintf("https://scoresaber.com/api/players?countries=%s&page=%d", country, (offset-1)/50+1)
|
||||
|
||||
// 创建请求
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user