From 8f91ac21df688865fd57ce222d81e3103e2426f6 Mon Sep 17 00:00:00 2001 From: lixiangwuxian Date: Sat, 12 Apr 2025 21:27:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E5=88=86=E6=95=B0=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E5=88=86=E9=A1=B5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BB=A5=E5=A4=84=E7=90=86=E8=B6=85=E8=BF=87?= =?UTF-8?q?8=E6=9D=A1=E8=AE=B0=E5=BD=95=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/scoresaber/bind_ss.go | 112 +++++++++++++++++----------------- 1 file changed, 57 insertions(+), 55 deletions(-) diff --git a/service/scoresaber/bind_ss.go b/service/scoresaber/bind_ss.go index e5b7c3d..13c994c 100644 --- a/service/scoresaber/bind_ss.go +++ b/service/scoresaber/bind_ss.go @@ -329,72 +329,74 @@ func (ss *ssQuery) GetRecentScores(count int, qqId string) ([]RecordDataLite, er if err != nil { return nil, err } - - historyUrl := "https://scoresaber.com/api/player/%s/scores?page=1&sort=recent" - fullUrl := fmt.Sprintf(historyUrl, ssId) - resp, err := http.Get(fullUrl) - if err != nil { - return nil, err - } - defer resp.Body.Close() - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } + //一页8条,超过8条则取两页 + historyUrl := "https://scoresaber.com/api/player/%s/scores?page=%d&sort=recent" var response struct { Data []struct { Score Score `json:"score"` Leaderboard Leaderboard `json:"leaderboard"` } `json:"playerScores"` } - err = json.Unmarshal(body, &response) - if err != nil { - return nil, err - } - scores := response.Data records := make([]RecordDataLite, 0) - for k, score := range scores { - if k > count-1 { - break + for i := 0; i < count/8; i++ { + fullUrl := fmt.Sprintf(historyUrl, ssId, i+1) + resp, err := http.Get(fullUrl) + if err != nil { + return nil, err } - record := RecordDataLite{ - ScoreID: score.Score.ID, - SsID: ssId, - Name: playerData.Name, - Country: playerData.Country, - SongName: score.Leaderboard.SongName, - SongSubName: score.Leaderboard.SongSubName, - SongAuthorName: score.Leaderboard.SongAuthorName, - SongHash: score.Leaderboard.SongHash, - SongId: "", - CoverImage: score.Leaderboard.CoverImage, - DifficultyRaw: score.Leaderboard.Difficulty.DifficultyRaw, - Stars: score.Leaderboard.Stars, - PP: score.Score.Pp, - Weight: score.Score.Weight, - Modifiers: score.Score.Modifiers, - Multiplier: score.Score.Multiplier, - Rank: score.Score.Rank, - BadCuts: score.Score.BadCuts, - Score: score.Score.ModifiedScore, - MaxScore: score.Leaderboard.MaxScore, - FullCombo: score.Score.FullCombo, - DeviceHmd: "", - DeviceControllerLeft: "", - DeviceControllerRight: "", - GeneratedTime: score.Score.TimeSet.Format("2006-01-02 15:04:05.999999999-07:00"), + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err } - // 检查设备信息并设置 - if score.Score.DeviceHmd != nil { - record.DeviceHmd = *score.Score.DeviceHmd + err = json.Unmarshal(body, &response) + if err != nil { + return nil, err } - if score.Score.DeviceControllerLeft != nil { - record.DeviceControllerLeft = *score.Score.DeviceControllerLeft + scores := response.Data + for k, score := range scores { + if k > count-1 { + break + } + record := RecordDataLite{ + ScoreID: score.Score.ID, + SsID: ssId, + Name: playerData.Name, + Country: playerData.Country, + SongName: score.Leaderboard.SongName, + SongSubName: score.Leaderboard.SongSubName, + SongAuthorName: score.Leaderboard.SongAuthorName, + SongHash: score.Leaderboard.SongHash, + SongId: "", + CoverImage: score.Leaderboard.CoverImage, + DifficultyRaw: score.Leaderboard.Difficulty.DifficultyRaw, + Stars: score.Leaderboard.Stars, + PP: score.Score.Pp, + Weight: score.Score.Weight, + Modifiers: score.Score.Modifiers, + Multiplier: score.Score.Multiplier, + Rank: score.Score.Rank, + BadCuts: score.Score.BadCuts, + Score: score.Score.ModifiedScore, + MaxScore: score.Leaderboard.MaxScore, + FullCombo: score.Score.FullCombo, + DeviceHmd: "", + DeviceControllerLeft: "", + DeviceControllerRight: "", + GeneratedTime: score.Score.TimeSet.Format("2006-01-02 15:04:05.999999999-07:00"), + } + // 检查设备信息并设置 + if score.Score.DeviceHmd != nil { + record.DeviceHmd = *score.Score.DeviceHmd + } + if score.Score.DeviceControllerLeft != nil { + record.DeviceControllerLeft = *score.Score.DeviceControllerLeft + } + if score.Score.DeviceControllerRight != nil { + record.DeviceControllerRight = *score.Score.DeviceControllerRight + } + records = append(records, record) } - if score.Score.DeviceControllerRight != nil { - record.DeviceControllerRight = *score.Score.DeviceControllerRight - } - records = append(records, record) } // 获取歌曲ID hashs := make([]string, 0)