feat: 更新 blPlus 函数以支持获取当前用户所在区对应 + N 位的玩家列表,并修正 PlayerData 中的字段名为大写形式
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user