2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/utils/httputil"
|
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.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Emojis(guildID discord.GuildID) ([]discord.Emoji, error) {
|
2020-07-29 23:29:01 +00:00
|
|
|
var e []discord.Emoji
|
|
|
|
return e, c.RequestJSON(&e, "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.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Emoji(guildID discord.GuildID, emojiID discord.EmojiID) (*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"`
|
2020-11-03 17:13:56 +00:00
|
|
|
// Roles are the roles that can use the emoji.
|
2020-07-21 20:27:59 +00:00
|
|
|
Roles *[]discord.RoleID `json:"roles,omitempty"`
|
2021-08-15 16:33:33 +00:00
|
|
|
|
|
|
|
AuditLogReason `json:"-"`
|
2020-05-11 22:06:19 +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
|
2021-08-15 16:33:33 +00:00
|
|
|
// "image/gif". However, ContentType can also be automatically detected (though
|
|
|
|
// shouldn't be relied on).
|
|
|
|
//
|
2020-05-11 22:06:19 +00:00
|
|
|
// Emojis and animated emojis have a maximum file size of 256kb.
|
2021-08-15 16:33:33 +00:00
|
|
|
func (c *Client) CreateEmoji(
|
|
|
|
guildID discord.GuildID, 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",
|
2021-08-15 16:33:33 +00:00
|
|
|
httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
|
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"`
|
2020-11-03 17:13:56 +00:00
|
|
|
// Roles are the roles that can use the emoji.
|
2020-07-21 20:27:59 +00:00
|
|
|
Roles *[]discord.RoleID `json:"roles,omitempty"`
|
2021-08-15 16:33:33 +00:00
|
|
|
|
|
|
|
AuditLogReason `json:"-"`
|
2020-05-11 22:06:19 +00:00
|
|
|
}
|
|
|
|
|
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.
|
2021-08-15 16:33:33 +00:00
|
|
|
func (c *Client) ModifyEmoji(
|
|
|
|
guildID discord.GuildID, emojiID discord.EmojiID, data ModifyEmojiData) error {
|
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
|
2021-08-15 16:33:33 +00:00
|
|
|
httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-08-15 16:33:33 +00:00
|
|
|
// DeleteEmoji deletes the given emoji.
|
2020-05-11 22:06:19 +00:00
|
|
|
//
|
|
|
|
// Requires the MANAGE_EMOJIS permission.
|
2021-08-15 16:33:33 +00:00
|
|
|
//
|
2020-05-11 22:06:19 +00:00
|
|
|
// Fires a Guild Emojis Update Gateway event.
|
2021-08-15 16:33:33 +00:00
|
|
|
func (c *Client) DeleteEmoji(
|
|
|
|
guildID discord.GuildID, emojiID discord.EmojiID, reason AuditLogReason) error {
|
|
|
|
|
|
|
|
return c.FastRequest(
|
|
|
|
"DELETE", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
|
|
|
|
httputil.WithHeaders(reason.Header()),
|
|
|
|
)
|
2020-01-04 04:19:24 +00:00
|
|
|
}
|