2020-01-16 04:27:57 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-04-09 02:28:40 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/httputil"
|
2020-05-11 03:24:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/json/option"
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Adds a role to a guild member.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error {
|
2020-05-12 02:05:08 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PUT",
|
|
|
|
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
|
|
|
)
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// RemoveRole removes a role from a guild member.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
|
|
|
// Fires a Guild Member Update Gateway event.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error {
|
2020-05-12 02:05:08 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"DELETE",
|
|
|
|
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
|
|
|
|
)
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Roles returns a list of role objects for the guild.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Roles(guildID discord.GuildID) ([]discord.Role, error) {
|
2020-01-16 04:27:57 +00:00
|
|
|
var roles []discord.Role
|
2020-05-12 02:05:08 +00:00
|
|
|
return roles, c.RequestJSON(&roles, "GET", EndpointGuilds+guildID.String()+"/roles")
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#create-guild-role-json-params
|
2020-05-11 03:24:59 +00:00
|
|
|
type CreateRoleData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// 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
|
2020-10-28 22:34:14 +00:00
|
|
|
Permissions discord.Permissions `json:"permissions,string,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// 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"`
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// CreateRole creates a new role for the guild.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
|
|
|
// Fires a Guild Role Create Gateway event.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error) {
|
2020-05-11 22:06:19 +00:00
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
var role *discord.Role
|
|
|
|
return role, c.RequestJSON(
|
|
|
|
&role, "POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/roles",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params
|
|
|
|
type MoveRoleData struct {
|
|
|
|
// ID is the id of the role.
|
2020-07-21 20:27:59 +00:00
|
|
|
ID discord.RoleID `json:"id"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Position is the sorting position of the role.
|
|
|
|
Position option.NullableInt `json:"position,omitempty"`
|
|
|
|
}
|
2020-01-16 04:27:57 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// 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.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) MoveRole(guildID discord.GuildID, data []MoveRoleData) ([]discord.Role, error) {
|
2020-01-16 04:27:57 +00:00
|
|
|
var roles []discord.Role
|
|
|
|
return roles, c.RequestJSON(
|
|
|
|
&roles, "PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/roles",
|
2020-05-11 22:06:19 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#modify-guild-role-json-params
|
2020-05-11 03:24:59 +00:00
|
|
|
type ModifyRoleData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Name is the name of the role.
|
|
|
|
Name option.NullableString `json:"name,omitempty"`
|
|
|
|
// Permissions is the bitwise value of the enabled/disabled permissions.
|
2020-10-28 22:34:14 +00:00
|
|
|
Permissions *discord.Permissions `json:"permissions,string,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// 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"`
|
2020-05-11 03:24:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ModifyRole modifies a guild role.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
2020-01-16 04:27:57 +00:00
|
|
|
func (c *Client) ModifyRole(
|
2020-07-21 20:27:59 +00:00
|
|
|
guildID discord.GuildID, roleID discord.RoleID,
|
2020-05-11 03:24:59 +00:00
|
|
|
data ModifyRoleData) (*discord.Role, error) {
|
2020-01-16 04:27:57 +00:00
|
|
|
|
|
|
|
var role *discord.Role
|
|
|
|
return role, c.RequestJSON(
|
|
|
|
&role, "PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// DeleteRole deletes a guild role.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_ROLES permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) DeleteRole(guildID discord.GuildID, roleID discord.RoleID) error {
|
2020-05-12 02:05:08 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"DELETE",
|
|
|
|
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
|
|
|
|
)
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|