/
role.go
134 lines (121 loc) · 4.3 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package api
import (
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/utils/httputil"
"github.com/diamondburned/arikawa/utils/json/option"
)
// Adds a role to a guild member.
//
// Requires the MANAGE_ROLES permission.
func (c *Client) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error {
return c.FastRequest(
"PUT",
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
)
}
// RemoveRole removes a role from a guild member.
//
// Requires the MANAGE_ROLES permission.
// Fires a Guild Member Update Gateway event.
func (c *Client) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error {
return c.FastRequest(
"DELETE",
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
)
}
// Roles returns a list of role objects for the guild.
func (c *Client) Roles(guildID discord.GuildID) ([]discord.Role, error) {
var roles []discord.Role
return roles, c.RequestJSON(&roles, "GET", EndpointGuilds+guildID.String()+"/roles")
}
// https://discord.com/developers/docs/resources/guild#create-guild-role-json-params
type CreateRoleData struct {
// Name is the name of the role.
//
// Default: "new role"
Name string `json:"name,omitempty"`
// Permissions is the bitwise value of the enabled/disabled permissions.
//
// Default: @everyone permissions in guild
Permissions discord.Permissions `json:"permissions,omitempty,string"`
// Color is the RGB color value of the role.
//
// Default: 0
Color discord.Color `json:"color,omitempty"`
// Hoist specifies whether the role should be displayed separately in the
// sidebar.
//
// Default: false
Hoist bool `json:"hoist,omitempty"`
// Mentionable specifies whether the role should be mentionable.
//
// Default: false
Mentionable bool `json:"mentionable,omitempty"`
}
// CreateRole creates a new role for the guild.
//
// Requires the MANAGE_ROLES permission.
// Fires a Guild Role Create Gateway event.
func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error) {
var role *discord.Role
return role, c.RequestJSON(
&role, "POST",
EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data),
)
}
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params
type MoveRoleData struct {
// ID is the id of the role.
ID discord.RoleID `json:"id"`
// Position is the sorting position of the role.
Position option.NullableInt `json:"position,omitempty"`
}
// MoveRole modifies the positions of a set of role objects for the guild.
//
// Requires the MANAGE_ROLES permission.
// Fires multiple Guild Role Update Gateway events.
func (c *Client) MoveRole(guildID discord.GuildID, data []MoveRoleData) ([]discord.Role, error) {
var roles []discord.Role
return roles, c.RequestJSON(
&roles, "PATCH",
EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data),
)
}
// https://discord.com/developers/docs/resources/guild#modify-guild-role-json-params
type ModifyRoleData struct {
// Name is the name of the role.
Name option.NullableString `json:"name,omitempty"`
// Permissions is the bitwise value of the enabled/disabled permissions.
Permissions *discord.Permissions `json:"permissions,omitempty,string"`
// Permissions is the bitwise value of the enabled/disabled permissions.
Color option.NullableColor `json:"color,omitempty"`
// Hoist specifies whether the role should be displayed separately in the
// sidebar.
Hoist option.NullableBool `json:"hoist,omitempty"`
// Mentionable specifies whether the role should be mentionable.
Mentionable option.NullableBool `json:"mentionable,omitempty"`
}
// ModifyRole modifies a guild role.
//
// Requires the MANAGE_ROLES permission.
func (c *Client) ModifyRole(
guildID discord.GuildID, roleID discord.RoleID,
data ModifyRoleData) (*discord.Role, error) {
var role *discord.Role
return role, c.RequestJSON(
&role, "PATCH",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
httputil.WithJSONBody(data),
)
}
// DeleteRole deletes a guild role.
//
// Requires the MANAGE_ROLES permission.
func (c *Client) DeleteRole(guildID discord.GuildID, roleID discord.RoleID) error {
return c.FastRequest(
"DELETE",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
)
}