/
role.go
86 lines (73 loc) · 2.47 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package discord
import (
"time"
"github.com/disgoorg/disgo/json"
"github.com/disgoorg/snowflake/v2"
)
var _ Mentionable = (*Role)(nil)
// Role is a Guild Role object
type Role struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
Color int `json:"color"`
Hoist bool `json:"hoist"`
Position int `json:"position"`
Permissions Permissions `json:"permissions"`
Managed bool `json:"managed"`
Icon *string `json:"icon"`
Emoji *string `json:"unicode_emoji"`
Mentionable bool `json:"mentionable"`
Tags *RoleTag `json:"tags,omitempty"`
}
func (r Role) String() string {
return RoleMention(r.ID)
}
func (r Role) Mention() string {
return r.String()
}
func (r Role) IconURL(opts ...CDNOpt) *string {
if r.Icon == nil {
return nil
}
url := formatAssetURL(RoleIcon, opts, r.ID, *r.Icon)
return &url
}
func (r Role) CreatedAt() time.Time {
return r.ID.Time()
}
// RoleTag are tags a Role has
type RoleTag struct {
BotID *snowflake.ID `json:"bot_id,omitempty"`
IntegrationID *snowflake.ID `json:"integration_id,omitempty"`
PremiumSubscriber bool `json:"premium_subscriber"`
}
// RoleCreate is the payload to create a Role
type RoleCreate struct {
Name string `json:"name,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
Color int `json:"color,omitempty"`
Hoist bool `json:"hoist,omitempty"`
Icon *Icon `json:"icon,omitempty"`
Emoji string `json:"unicode_emoji,omitempty"`
Mentionable bool `json:"mentionable,omitempty"`
}
// RoleUpdate is the payload to update a Role
type RoleUpdate struct {
Name *string `json:"name,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
Color *int `json:"color,omitempty"`
Hoist *bool `json:"hoist,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
Emoji *string `json:"unicode_emoji,omitempty"`
Mentionable *bool `json:"mentionable,omitempty"`
}
// RolePositionUpdate is the payload to update a Role(s) position
type RolePositionUpdate struct {
ID snowflake.ID `json:"id"`
Position *int `json:"position,omitempty"`
}
// PartialRole holds basic info about a Role
type PartialRole struct {
ID snowflake.ID `json:"id"`
Name string `json:"name"`
}