1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-09 16:35:12 +00:00
arikawa/api/role.go

89 lines
2.6 KiB
Go
Raw Normal View History

2020-01-16 04:27:57 +00:00
package api
import (
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/utils/httputil"
"github.com/diamondburned/arikawa/utils/json/option"
2020-01-16 04:27:57 +00:00
)
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 {
2020-01-16 04:27:57 +00:00
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) {
2020-01-16 04:27:57 +00:00
var role *discord.Role
return role, c.RequestJSON(
&role, "POST",
EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data),
2020-01-16 04:27:57 +00:00
)
}
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),
2020-01-16 04:27:57 +00:00
)
}
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
}
2020-01-16 04:27:57 +00:00
func (c *Client) ModifyRole(
guildID, roleID discord.Snowflake,
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(),
httputil.WithJSONBody(data),
2020-01-16 04:27:57 +00:00
)
}
func (c *Client) DeleteRole(guildID, roleID discord.Snowflake) error {
return c.FastRequest("DELETE",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String())
}