-
Notifications
You must be signed in to change notification settings - Fork 2
/
topdonors.go
80 lines (70 loc) · 2.11 KB
/
topdonors.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
77
78
79
80
package hmrapi
import (
"github.com/osu-datenshi/api/common"
)
type userData struct {
ID int `json:"id"`
Username string `json:"username"`
UsernameAKA string `json:"username_aka"`
RegisteredOn common.UnixTimestamp `json:"registered_on"`
LatestActivity common.UnixTimestamp `json:"latest_activity"`
Country string `json:"country"`
Expiration common.UnixTimestamp `json:"expiration"`
}
type topDonorsResponse struct {
common.ResponseBase
Users []userData `json:"users"`
}
const lbUserQuery = `
SELECT
users.id, users.username, user_config.username_aka, users.register_datetime, users.privileges, users.latest_activity,
user_config.country, users.donor_expire
FROM users
INNER JOIN user_config ON user_config.id = users.id
WHERE users.privileges >= 4 AND users.privileges != 1048576
ORDER BY users.donor_expire DESC
`
func TopDonorsGET(md common.MethodData) common.CodeMessager {
var resp topDonorsResponse
resp.Code = 200
var tempUsers []userData
rows, err := md.DB.Query(lbUserQuery)
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!")
}
defer rows.Close()
for rows.Next() {
var u userData
var privileges uint64
err := rows.Scan(
&u.ID, &u.Username, &u.UsernameAKA, &u.RegisteredOn, &privileges, &u.LatestActivity,
&u.Country, &u.Expiration,
)
if err != nil {
md.Err(err)
continue
}
var HasDonor, IsCheat bool
HasDonor = common.UserPrivileges(privileges)&common.UserPrivilegeDonor > 0
IsCheat = common.UserPrivileges(privileges)&common.AdminPrivilegeAccessRAP > 0
if IsCheat {
continue
}
if HasDonor {
tempUsers = append(tempUsers, u)
} else {
continue
}
}
if len(tempUsers)>100 {
sortedUsers := make([]userData, 100)
copy(sortedUsers, tempUsers)
resp.Users = sortedUsers
} else {
resp.Users = tempUsers
}
return resp
}
//Thank you Kurikku!!
//https://github.com/osukurikku/api/blob/master/vendor/github.com/KotRikD/krapi/topdonors.go