-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.go
67 lines (54 loc) · 1.59 KB
/
role.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
package objects
import (
"encoding/json"
"strconv"
"github.com/Postcord/objects/permissions"
)
var _ Mentionable = (*Role)(nil)
var _ SnowflakeObject = (*Role)(nil)
type Role struct {
DiscordBaseObject
Name string `json:"name"`
Color int `json:"color"`
Hoist bool `json:"hoist"`
Icon string `json:"icon"`
UnicodeEmoji string `json:"unicode_emoji"`
Position int `json:"position"`
Permissions permissions.PermissionBit `json:"permissions"`
Managed bool `json:"managed"`
Mentionable bool `json:"mentionable"`
Tags RoleTags `json:"tags"`
}
type RoleTags struct {
BotID Snowflake `json:"bot_id"`
IntegrationID Snowflake `json:"integration_id"`
PremiumSubscriber bool
}
func (r *RoleTags) UnmarshalJSON(in []byte) error {
var m map[string]interface{}
err := json.Unmarshal(in, &m)
if err != nil {
return err
}
if _, exists := m["premium_subscriber"]; exists {
r.PremiumSubscriber = true
}
if botID, exists := m["bot_id"]; exists {
intSnow, err := strconv.ParseUint(botID.(string), 10, 64)
if err != nil {
return err
}
r.BotID = Snowflake(intSnow)
}
if integrationID, exists := m["integration_id"]; exists {
intSnow, err := strconv.ParseUint(integrationID.(string), 10, 64)
if err != nil {
return err
}
r.IntegrationID = Snowflake(intSnow)
}
return nil
}
func (r *Role) Mention() string {
return "<@&" + r.ID.String() + ">"
}