1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-08 07:54:58 +00:00
arikawa/api/role.go
2020-05-11 05:24:59 +02:00

89 lines
2.6 KiB
Go

package api
import (
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/utils/httputil"
"github.com/diamondburned/arikawa/utils/json/option"
)
func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
return c.FastRequest("PUT", EndpointGuilds+guildID.String()+
"/members/"+userID.String()+
"/roles/"+roleID.String())
}
func (c *Client) RemoveRole(guildID, userID, roleID discord.Snowflake) error {
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+
"/members/"+userID.String()+
"/roles/"+roleID.String())
}
func (c *Client) Roles(guildID discord.Snowflake) ([]discord.Role, error) {
var roles []discord.Role
return roles, c.RequestJSON(&roles, "GET",
EndpointGuilds+guildID.String()+"/roles")
}
type CreateRoleData struct {
Name string `json:"name,omitempty"` // "new role"
Color discord.Color `json:"color,omitempty"` // 0
Hoist bool `json:"hoist,omitempty"` // false (show role separately)
Mentionable bool `json:"mentionable,omitempty"` // false
Permissions discord.Permissions `json:"permissions,omitempty"` // @everyone
}
func (c *Client) CreateRole(guildID discord.Snowflake, data CreateRoleData) (*discord.Role, error) {
var role *discord.Role
return role, c.RequestJSON(
&role, "POST",
EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data),
)
}
func (c *Client) MoveRole(
guildID, roleID discord.Snowflake, position int) ([]discord.Role, error) {
var param struct {
ID discord.Snowflake `json:"id"`
Pos int `json:"position"`
}
param.ID = roleID
param.Pos = position
var roles []discord.Role
return roles, c.RequestJSON(
&roles, "PATCH",
EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(param),
)
}
type ModifyRoleData struct {
Name string `json:"name,omitempty"` // "new role"
Color option.Color `json:"color,omitempty"` // 0
Hoist option.Bool `json:"hoist,omitempty"` // false (show role separately)
Mentionable option.Bool `json:"mentionable,omitempty"` // false
Permissions discord.Permissions `json:"permissions,omitempty"` // @everyone
}
func (c *Client) ModifyRole(
guildID, roleID discord.Snowflake,
data ModifyRoleData) (*discord.Role, error) {
var role *discord.Role
return role, c.RequestJSON(
&role, "PATCH",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
httputil.WithJSONBody(data),
)
}
func (c *Client) DeleteRole(guildID, roleID discord.Snowflake) error {
return c.FastRequest("DELETE",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String())
}