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
|
|
|
)
|
|
|
|
|
2020-05-14 07:49:57 +00:00
|
|
|
// Emoji is the API format of a regular Emoji, both Unicode or custom. This
|
|
|
|
// could usually be formatted by calling (discord.Emoji).APIString().
|
2020-05-11 19:03:33 +00:00
|
|
|
type Emoji = string
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-12 00:17:45 +00:00
|
|
|
// NewCustomEmoji creates a new Emoji using a custom guild emoji as
|
2020-05-11 19:03:33 +00:00
|
|
|
// base.
|
2020-05-12 00:11:04 +00:00
|
|
|
// Unicode emojis should be directly passed to the function using Emoji.
|
2020-05-12 00:17:45 +00:00
|
|
|
func NewCustomEmoji(id discord.Snowflake, name string) Emoji {
|
2020-03-22 22:23:29 +00:00
|
|
|
return name + ":" + id.String()
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Emojis returns a list of emoji objects for the given guild.
|
|
|
|
func (c *Client) Emojis(guildID discord.Snowflake) ([]discord.Emoji, error) {
|
2020-01-02 19:53:08 +00:00
|
|
|
var emjs []discord.Emoji
|
2020-05-11 22:06:19 +00:00
|
|
|
return emjs, c.RequestJSON(&emjs, "GET", EndpointGuilds+guildID.String()+"/emojis")
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Emoji returns an emoji object for the given guild and emoji IDs.
|
|
|
|
func (c *Client) Emoji(guildID, emojiID discord.Snowflake) (*discord.Emoji, error) {
|
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-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/emoji#create-guild-emoji-json-params
|
|
|
|
type CreateEmojiData struct {
|
|
|
|
// Name is the name of the emoji.
|
|
|
|
Name string `json:"name"`
|
|
|
|
// Image is the the 128x128 emoji image.
|
|
|
|
Image Image `json:"image"`
|
|
|
|
// Roles are the roles for which this emoji will be whitelisted.
|
|
|
|
Roles *[]discord.Snowflake `json:"roles,omitempty"`
|
|
|
|
}
|
|
|
|
|
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
|
2020-05-11 22:06:19 +00:00
|
|
|
// (though shouldn't be relied on).
|
|
|
|
// Emojis and animated emojis have a maximum file size of 256kb.
|
2020-01-04 04:19:24 +00:00
|
|
|
func (c *Client) CreateEmoji(
|
2020-05-11 22:06:19 +00:00
|
|
|
guildID discord.Snowflake, data CreateEmojiData) (*discord.Emoji, error) {
|
2020-01-04 04:19:24 +00:00
|
|
|
|
2020-05-07 21:29:46 +00:00
|
|
|
// Max 256KB
|
2020-05-11 22:06:19 +00:00
|
|
|
if err := data.Image.Validate(256 * 1000); err != nil {
|
2020-01-04 04:19:24 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var emj *discord.Emoji
|
|
|
|
return emj, c.RequestJSON(
|
|
|
|
&emj, "POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis",
|
2020-05-11 22:06:19 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/emoji#modify-guild-emoji-json-params
|
|
|
|
type ModifyEmojiData struct {
|
|
|
|
// Name is the name of the emoji.
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
// Roles are the roles to which this emoji will be whitelisted.
|
|
|
|
Roles *[]discord.Snowflake `json:"roles,omitempty"`
|
|
|
|
}
|
|
|
|
|
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).
|
2020-05-11 22:06:19 +00:00
|
|
|
//
|
|
|
|
// Fires a Guild Emojis Update Gateway event.
|
|
|
|
func (c *Client) ModifyEmoji(guildID, emojiID discord.Snowflake, data ModifyEmojiData) error {
|
2020-01-04 04:19:24 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
|
2020-05-11 22:06:19 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Delete the given emoji.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_EMOJIS permission.
|
|
|
|
// Fires a Guild Emojis Update Gateway event.
|
2020-01-04 04:19:24 +00:00
|
|
|
func (c *Client) DeleteEmoji(guildID, emojiID discord.Snowflake) error {
|
2020-05-11 22:06:19 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String())
|
2020-01-04 04:19:24 +00:00
|
|
|
}
|