-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathstaff.go
79 lines (67 loc) · 1.37 KB
/
staff.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
package main
import "github.com/bwmarrin/discordgo"
// Higher (lower index) is better
var staffRoles = []Role{
HeadDev,
Developer,
SeniorMod,
Moderator,
Support,
}
func (r Role) IsAtLeast(role Role) bool {
for _, testRole := range staffRoles {
switch testRole {
case role:
return true
case r:
return false
}
}
return false
}
func (r Role) IsHigherThan(role Role) bool {
for _, testRole := range staffRoles {
switch testRole {
case r:
return false
case role:
return true
}
}
return false
}
func GetRolesAtLeast(role Role) []Role {
return staffRoles[:GetRank(role)+1]
}
func GetRolesHigherThan(role Role) []Role {
return staffRoles[:GetRank(role)]
}
// Lower is better, -1 is not found
func GetRank(role Role) int {
for i, r := range staffRoles {
if r == role {
return i
}
}
return -1
}
func IsUserStaff(user *discordgo.Member) bool {
return hasRole(user, staffRoles...)
}
func IsUserAtLeast(user *discordgo.Member, role Role) bool {
return hasRole(user, GetRolesAtLeast(role)...)
}
func IsUserHigherThan(user *discordgo.Member, role Role) bool {
return hasRole(user, GetRolesHigherThan(role)...)
}
func IsUserLowerThan(user *discordgo.Member, role Role) bool {
return !IsUserAtLeast(user, role)
}
func GetHighestStaffRole(user *discordgo.Member) int {
for i, r := range staffRoles {
if hasRole(user, r) {
return i
}
}
return -1
}