diff --git a/src/client/ClientDataManager.js b/src/client/ClientDataManager.js index 32b442b73..e663e107e 100644 --- a/src/client/ClientDataManager.js +++ b/src/client/ClientDataManager.js @@ -123,6 +123,7 @@ class ClientDataManager { const oldEmoji = cloneObject(currentEmoji); currentEmoji.setup(newData); this.client.emit(Constants.Events.GUILD_EMOJI_UPDATE, oldEmoji, currentEmoji); + return currentEmoji; } } diff --git a/src/client/actions/GuildEmojiUpdate.js b/src/client/actions/GuildEmojiUpdate.js index 94bfa24d9..593e54b2d 100644 --- a/src/client/actions/GuildEmojiUpdate.js +++ b/src/client/actions/GuildEmojiUpdate.js @@ -2,7 +2,10 @@ const Action = require('./Action'); class GuildEmojiUpdateAction extends Action { handle(oldEmoji, newEmoji) { - this.client.dataManager.updateEmoji(oldEmoji, newEmoji); + const emoji = this.client.dataManager.updateEmoji(oldEmoji, newEmoji); + return { + emoji, + }; } } diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 96920e035..4e65257ab 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -564,6 +564,14 @@ class RESTMethods { .then(data => this.client.actions.GuildEmojiCreate.handle(data, guild).emoji); } + updateEmoji(emoji, _data) { + const data = {}; + if (_data.name) data.name = _data.name; + if (_data.roles) data.roles = _data.roles.map(r => r.id ? r.id : r); + return this.rest.makeRequest('patch', Constants.Endpoints.guildEmoji(emoji.guild.id, emoji.id), true, data) + .then(newEmoji => this.client.actions.GuildEmojiUpdate.handle(emoji, newEmoji).emoji); + } + deleteEmoji(emoji) { return this.rest.makeRequest('delete', `${Constants.Endpoints.guildEmojis(emoji.guild.id)}/${emoji.id}`, true) .then(() => this.client.actions.GuildEmojiDelete.handle(emoji).data); diff --git a/src/structures/Emoji.js b/src/structures/Emoji.js index 519092c28..b860e25c6 100644 --- a/src/structures/Emoji.js +++ b/src/structures/Emoji.js @@ -101,6 +101,27 @@ class Emoji { return encodeURIComponent(this.name); } + /** + * Data for editing an emoji + * @typedef {Object} EmojiEditData + * @property {string} [name] The name of the emoji + * @property {Collection|Array} [roles] Roles to restrict emoji to + */ + + /** + * Edits the emoji + * @param {EmojiEditData} data The new data for the emoji + * @returns {Promise} + * @example + * // edit a emoji + * emoji.edit({name: 'newemoji'}) + * .then(e => console.log(`Edited emoji ${e}`)) + * .catch(console.error); + */ + edit(data) { + return this.client.rest.methods.updateEmoji(this, data); + } + /** * When concatenated with a string, this automatically returns the emoji mention rather than the object. * @returns {string} diff --git a/src/util/Constants.js b/src/util/Constants.js index 48f1cfec9..130ede43f 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -125,6 +125,7 @@ const Endpoints = exports.Endpoints = { guildMemberNickname: (guildID) => `${Endpoints.guildMember(guildID, '@me')}/nick`, guildChannels: (guildID) => `${Endpoints.guild(guildID)}/channels`, guildEmojis: (guildID) => `${Endpoints.guild(guildID)}/emojis`, + guildEmoji: (guildID, emojiID) => `${Endpoints.guildEmojis(guildID)}/${emojiID}`, guildSearch: (guildID) => `${Endpoints.guild(guildID)}/messages/search`, guildVoiceRegions: (guildID) => `${Endpoints.guild(guildID)}/regions`,