From a36a65b36ab5f91edad9b0d086528b534f1c4137 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Tue, 17 Mar 2020 17:52:43 +0000 Subject: [PATCH] fix(MessageReaction): fetching a removed partial custom emoji (#3955) * fix: handling GuildEmoji within fetch() * refactor: remove unused "private" methods * refactor: make use of Message#fetch() to patch --- src/managers/ReactionManager.js | 26 -------------------------- src/structures/MessageReaction.js | 8 ++++++-- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/src/managers/ReactionManager.js b/src/managers/ReactionManager.js index b82176892..b46d1876c 100644 --- a/src/managers/ReactionManager.js +++ b/src/managers/ReactionManager.js @@ -64,32 +64,6 @@ class ReactionManager extends BaseManager { .reactions.delete() .then(() => this.message); } - - _partial(emoji) { - const id = emoji.id || emoji.name; - const existing = this.cache.get(id); - return !existing || existing.partial; - } - - async _fetchReaction(reactionEmoji, cache) { - const id = reactionEmoji.id || reactionEmoji.name; - const existing = this.cache.get(id); - if (!this._partial(reactionEmoji)) return existing; - const data = await this.client.api - .channels(this.message.channel.id) - .messages(this.message.id) - .get(); - if (this.message.partial) this.message._patch(data); - if (!data.reactions || !data.reactions.some(r => (r.emoji.id || r.emoji.name) === id)) { - reactionEmoji.reaction._patch({ count: 0 }); - this.message.reactions.cache.delete(id); - return existing; - } - for (const reaction of data.reactions) { - if (this._partial(reaction.emoji)) this.add(reaction, cache); - } - return existing; - } } module.exports = ReactionManager; diff --git a/src/structures/MessageReaction.js b/src/structures/MessageReaction.js index fae23916b..7b08e6517 100644 --- a/src/structures/MessageReaction.js +++ b/src/structures/MessageReaction.js @@ -101,8 +101,12 @@ class MessageReaction { * Fetch this reaction. * @returns {Promise} */ - fetch() { - return this.message.reactions._fetchReaction(this.emoji, true); + async fetch() { + const message = await this.message.fetch(); + const existing = message.reactions.cache.get(this.emoji.id || this.emoji.name); + // The reaction won't get set when it has been completely removed + this._patch(existing || { count: 0 }); + return this; } toJSON() {