-
Notifications
You must be signed in to change notification settings - Fork 2
/
mostplayedbm.go
76 lines (67 loc) · 2.36 KB
/
mostplayedbm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package hmrapi
import (
"github.com/osu-datenshi/api/common"
)
type difficulty struct {
STD float64 `json:"std"`
Taiko float64 `json:"taiko"`
CTB float64 `json:"ctb"`
Mania float64 `json:"mania"`
}
type beatmap struct {
BeatmapID int `json:"beatmap_id"`
BeatmapsetID int `json:"beatmapset_id"`
BeatmapMD5 string `json:"beatmap_md5"`
SongName string `json:"song_name"`
AR float32 `json:"ar"`
OD float32 `json:"od"`
Difficulty float64 `json:"difficulty"`
Diff2 difficulty `json:"difficulty2"`
MaxCombo int `json:"max_combo"`
HitLength int `json:"hit_length"`
Ranked int `json:"ranked"`
RankedStatusFrozen int `json:"ranked_status_frozen"`
LatestUpdate common.UnixTimestamp `json:"latest_update"`
PlayCount int `json:"playcount"`
BPM int `json:"bpm"`
}
type beatmapsResponse struct {
common.ResponseBase
Beatmaps []beatmap `json:"beatmaps"`
}
const baseBeatmapSelect = `
SELECT
beatmap_id, beatmapset_id, beatmap_md5,
song_name, ar, od, difficulty_std, difficulty_taiko,
difficulty_ctb, difficulty_mania, max_combo,
hit_length, ranked, ranked_status_freezed,
latest_update, playcount, bpm
FROM beatmaps
`
func Beatmaps5GET(md common.MethodData) common.CodeMessager {
var resp beatmapsResponse
resp.Code = 200
rows, err := md.DB.Query(baseBeatmapSelect + " ORDER BY playcount DESC LIMIT 5")
if err != nil {
md.Err(err)
return common.SimpleResponse(500, "Uh oh... Seems like Aoba did something bad to API... Please try again! If it's broken... Please tell me in the Discord!")
}
for rows.Next() {
var b beatmap
err := rows.Scan(
&b.BeatmapID, &b.BeatmapsetID, &b.BeatmapMD5,
&b.SongName, &b.AR, &b.OD, &b.Diff2.STD, &b.Diff2.Taiko,
&b.Diff2.CTB, &b.Diff2.Mania, &b.MaxCombo,
&b.HitLength, &b.Ranked, &b.RankedStatusFrozen,
&b.LatestUpdate, &b.PlayCount, &b.BPM,
)
if err != nil {
md.Err(err)
continue
}
resp.Beatmaps = append(resp.Beatmaps, b)
}
return resp
}
//Thank you Kurikku!!
//https://github.com/osukurikku/api/blob/master/vendor/github.com/KotRikD/krapi/mostplayedbm.go