-
Notifications
You must be signed in to change notification settings - Fork 2
/
realm.go
54 lines (43 loc) · 1.35 KB
/
realm.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
package caddydiscord
const (
Unknown DiscordResource = 0
DiscordGuildRule DiscordResource = 1
DiscordRoleRule DiscordResource = 2
// DiscordMemberRule represents a specific Discord User within a specific guild
DiscordMemberRule DiscordResource = 3
// DiscordUserRule represents a Discord User Snowflake ID
DiscordUserRule DiscordResource = 4
)
type DiscordResource int
func ResourceRequiresGuild(resource DiscordResource) bool {
switch resource {
case DiscordGuildRule, DiscordRoleRule, DiscordMemberRule:
return true
}
return false
}
type Realm struct {
Ref string `json:"Ref"`
Identifiers []*AccessIdentifier `json:"Identifiers"`
}
func (r Realm) GetAllGuilds() []string {
// Use map to avoid doubling up values
guildMap := make(map[string]bool)
for _, resource := range r.Identifiers {
switch resource.Resource {
case DiscordGuildRule, DiscordRoleRule, DiscordMemberRule:
guildMap[resource.GuildID] = true
}
}
guildIDs := make([]string, 0, len(guildMap))
for guildID := range guildMap {
guildIDs = append(guildIDs, guildID)
}
return guildIDs
}
type AccessIdentifier struct {
Resource DiscordResource `json:"Resource"` // role, user
Identifier string `json:"Identifier,omitempty"`
GuildID string `json:"GuildID,omitempty"`
Wildcard bool `json:"Wildcard,omitempty"`
}