From 8f686efd241c5355b1fb9e716ea073509b3fc3b6 Mon Sep 17 00:00:00 2001 From: Sebastian Winkler Date: Sun, 20 May 2018 14:37:02 +0200 Subject: [PATCH] adds GuildEmojiCreate, GuildEmojiEdit, and GuildEmojiDelete --- endpoints.go | 2 ++ restapi.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/endpoints.go b/endpoints.go index 2c69595..95f6fd9 100644 --- a/endpoints.go +++ b/endpoints.go @@ -95,6 +95,8 @@ var ( EndpointGuildSplash = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" } EndpointGuildWebhooks = func(gID string) string { return EndpointGuilds + gID + "/webhooks" } EndpointGuildAuditLogs = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" } + EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" } + EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID } EndpointChannel = func(cID string) string { return EndpointChannels + cID } EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" } diff --git a/restapi.go b/restapi.go index e5ef9f8..e4c7d2b 100644 --- a/restapi.go +++ b/restapi.go @@ -1285,6 +1285,56 @@ func (s *Session) GuildAuditLog(guildID, userID, beforeID string, actionType, li return } +// GuildEmojiCreate creates a new emoji +// guildID : The ID of a Guild. +// image : the base64 encoded emoji image, has to be smaller than 256KB +// roles : roles for which this emoji will be whitelisted, can be nil +func (s *Session) GuildEmojiCreate(guildID, name, image string, roles []string) (emoji *Emoji, err error) { + + data := struct { + Name string `json:"name"` + Image string `json:"image"` + Roles []string `json:"roles,omitempty"` + }{name, image, roles} + + body, err := s.RequestWithBucketID("POST", EndpointGuildEmojis(guildID), data, EndpointGuildEmojis(guildID)) + if err != nil { + return + } + + err = unmarshal(body, &emoji) + return +} + +// GuildEmojiEdit modifies an emoji +// guildID : The ID of a Guild. +// image : the base64 encoded emoji image, has to be smaller than 256KB +// roles : roles for which this emoji will be whitelisted, can be nil +func (s *Session) GuildEmojiEdit(guildID, emojiID, name string, roles []string) (emoji *Emoji, err error) { + + data := struct { + Name string `json:"name"` + Roles []string `json:"roles,omitempty"` + }{name, roles} + + body, err := s.RequestWithBucketID("PATCH", EndpointGuildEmoji(guildID, emojiID), data, EndpointGuildEmojis(guildID)) + if err != nil { + return + } + + err = unmarshal(body, &emoji) + return +} + +// GuildEmojiDelete deletes an Emoji. +// guildID : The ID of a Guild. +// emojiID : The ID of the Emoji. +func (s *Session) GuildEmojiDelete(guildID, emojiID string) (err error) { + + _, err = s.RequestWithBucketID("DELETE", EndpointGuildEmoji(guildID, emojiID), nil, EndpointGuildEmojis(guildID)) + return +} + // ------------------------------------------------------------------------------------------------ // Functions specific to Discord Channels // ------------------------------------------------------------------------------------------------