2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-01-02 19:55:45 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-04-09 02:28:40 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/httputil"
|
2020-01-02 05:39:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// EmojiAPI is a special format that the API wants.
|
|
|
|
type EmojiAPI = string
|
|
|
|
|
|
|
|
func FormatEmojiAPI(id discord.Snowflake, name string) string {
|
|
|
|
if id == 0 {
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2020-03-22 22:23:29 +00:00
|
|
|
return name + ":" + id.String()
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
func (c *Client) Emojis(
|
|
|
|
guildID discord.Snowflake) ([]discord.Emoji, error) {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
var emjs []discord.Emoji
|
|
|
|
return emjs, c.RequestJSON(&emjs, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis")
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
func (c *Client) Emoji(
|
|
|
|
guildID, emojiID discord.Snowflake) (*discord.Emoji, error) {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
var emj *discord.Emoji
|
|
|
|
return emj, c.RequestJSON(&emj, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String())
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
2020-01-02 19:53:08 +00:00
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
// CreateEmoji creates a new emoji in the guild. This endpoint requires
|
|
|
|
// MANAGE_EMOJIS. ContentType must be "image/jpeg", "image/png", or
|
|
|
|
// "image/gif". However, ContentType can also be automatically detected
|
|
|
|
// (though shouldn't be relied on). Roles slice is optional.
|
|
|
|
func (c *Client) CreateEmoji(
|
|
|
|
guildID discord.Snowflake, name string, image Image,
|
|
|
|
roles []discord.Snowflake) (*discord.Emoji, error) {
|
|
|
|
|
2020-05-07 21:29:46 +00:00
|
|
|
// Max 256KB
|
|
|
|
if err := image.Validate(256 * 1000); err != nil {
|
2020-01-04 04:19:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var param struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Image Image `json:"image"`
|
|
|
|
Roles []discord.Snowflake `json:"roles"`
|
|
|
|
}
|
|
|
|
|
|
|
|
param.Name = name
|
|
|
|
param.Roles = roles
|
|
|
|
param.Image = image
|
|
|
|
|
|
|
|
var emj *discord.Emoji
|
|
|
|
return emj, c.RequestJSON(
|
|
|
|
&emj, "POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(param),
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModifyEmoji changes an existing emoji. This requires MANAGE_EMOJIS. Name and
|
|
|
|
// roles are optional fields (though you'd want to change either though).
|
|
|
|
func (c *Client) ModifyEmoji(
|
|
|
|
guildID, emojiID discord.Snowflake, name string,
|
|
|
|
roles []discord.Snowflake) error {
|
|
|
|
|
|
|
|
var param struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Roles []discord.Snowflake `json:"roles,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-05-07 22:47:08 +00:00
|
|
|
param.Name = name
|
|
|
|
param.Roles = roles
|
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(param),
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteEmoji requires MANAGE_EMOJIS.
|
|
|
|
func (c *Client) DeleteEmoji(guildID, emojiID discord.Snowflake) error {
|
|
|
|
return c.FastRequest("DELETE",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String())
|
|
|
|
}
|