From 42f084598f428366e42150fd488811cb172c23a3 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Mon, 11 Oct 2021 22:51:00 +0100 Subject: [PATCH 1/9] fix(Message): partial shenanigans --- src/structures/Message.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index aa51659a4ee1..d2471d55ab10 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -719,12 +719,15 @@ class Message extends Base { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); emoji = this.client.emojis.resolveIdentifier(emoji); await this.channel.messages.react(this.id, emoji); - return this.client.actions.MessageReactionAdd.handle({ - user: this.client.user, - channel: this.channel, - message: this, + + const reaction = this.reactions._add({ emoji: Util.parseEmoji(emoji), - }).reaction; + count: this.partial ? null : 0, + me: true, + }); + + reaction._add(this.client.user); + return reaction; } /** From 95b3cd6bdbb1fa1fc565aeef4fb22a4220e83002 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Mon, 11 Oct 2021 23:23:53 +0100 Subject: [PATCH 2/9] fix(Message): simply return `this` --- src/structures/Message.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index d2471d55ab10..7ea7493199d5 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -719,15 +719,7 @@ class Message extends Base { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); emoji = this.client.emojis.resolveIdentifier(emoji); await this.channel.messages.react(this.id, emoji); - - const reaction = this.reactions._add({ - emoji: Util.parseEmoji(emoji), - count: this.partial ? null : 0, - me: true, - }); - - reaction._add(this.client.user); - return reaction; + return this; } /** From 2b133d6373d992683195b76cdb4d3dc1fbfcf666 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 00:08:12 +0100 Subject: [PATCH 3/9] refactor(Message): why is this here? --- src/structures/Message.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 7ea7493199d5..7e0163a02bd0 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -717,7 +717,6 @@ class Message extends Base { */ async react(emoji) { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); - emoji = this.client.emojis.resolveIdentifier(emoji); await this.channel.messages.react(this.id, emoji); return this; } From 1b2e23fb23552b2ced6c9477e220c417760757fa Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 00:08:29 +0100 Subject: [PATCH 4/9] fix(Message): return correct type --- src/structures/Message.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 7e0163a02bd0..51d4ef6e6ded 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -718,7 +718,15 @@ class Message extends Base { async react(emoji) { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); await this.channel.messages.react(this.id, emoji); - return this; + + const reaction = this.reactions._add({ + emoji: Util.parseEmoji(emoji), + count: this.partial ? null : 0, + me: true, + }); + + reaction._add(this.client.user); + return reaction; } /** From 75ee5001a79f49f6d0558b33478926501069b151 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 18:53:13 +0100 Subject: [PATCH 5/9] fix: handle emoji objects --- src/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 51d4ef6e6ded..2ae89f6eae1e 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -720,7 +720,7 @@ class Message extends Base { await this.channel.messages.react(this.id, emoji); const reaction = this.reactions._add({ - emoji: Util.parseEmoji(emoji), + emoji: this.client.emojis.resolveIdentifier(emoji), count: this.partial ? null : 0, me: true, }); From 895413416c8d2428500706cecd64cadc01e20701 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 21:33:06 +0100 Subject: [PATCH 6/9] fix: return `RawEmoji` --- src/structures/Message.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 2ae89f6eae1e..767b7058d488 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -720,7 +720,7 @@ class Message extends Base { await this.channel.messages.react(this.id, emoji); const reaction = this.reactions._add({ - emoji: this.client.emojis.resolveIdentifier(emoji), + emoji: Util.resolvePartialEmoji(emoji), count: this.partial ? null : 0, me: true, }); From 39597e1535c5568a6705479eadfbc3c2bf1b1cb7 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 22:45:10 +0100 Subject: [PATCH 7/9] refactor: return if in cache Possible fix? --- src/structures/Message.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/structures/Message.js b/src/structures/Message.js index 767b7058d488..f2b2d73d677d 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -719,6 +719,9 @@ class Message extends Base { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); await this.channel.messages.react(this.id, emoji); + const cachedEmoji = this.channel.messages.cache.get(emoji?.id ?? emoji); + if (cachedEmoji) return cachedEmoji; + const reaction = this.reactions._add({ emoji: Util.resolvePartialEmoji(emoji), count: this.partial ? null : 0, From aab6a9e5df3dec43a67047e2bcfe089cb4f8cbb3 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 23:23:58 +0100 Subject: [PATCH 8/9] fix: try boolean logic in handler --- src/client/actions/MessageReactionAdd.js | 6 ++++-- src/structures/Message.js | 20 +++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/client/actions/MessageReactionAdd.js b/src/client/actions/MessageReactionAdd.js index 452ed6b12f05..d6a01425cdf9 100644 --- a/src/client/actions/MessageReactionAdd.js +++ b/src/client/actions/MessageReactionAdd.js @@ -15,7 +15,7 @@ const { PartialTypes } = require('../../util/Constants'); */ class MessageReactionAdd extends Action { - handle(data) { + handle(data, fromStructure = false) { if (!data.emoji) return false; const user = this.getUserFromMember(data); @@ -30,7 +30,8 @@ class MessageReactionAdd extends Action { if (!message) return false; // Verify reaction - if (message.partial && !this.client.options.partials.includes(PartialTypes.REACTION)) return false; + const includePartial = this.client.options.partials.includes(PartialTypes.REACTION); + if (message.partial && !includePartial) return false; const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name); if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user }; const reaction = message.reactions._add({ @@ -40,6 +41,7 @@ class MessageReactionAdd extends Action { }); if (!reaction) return false; reaction._add(user); + if (fromStructure && includePartial) return { message, reaction, user }; /** * Emitted whenever a reaction is added to a cached message. * @event Client#messageReactionAdd diff --git a/src/structures/Message.js b/src/structures/Message.js index f2b2d73d677d..5d173b9e607e 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -719,17 +719,15 @@ class Message extends Base { if (!this.channel) throw new Error('CHANNEL_NOT_CACHED'); await this.channel.messages.react(this.id, emoji); - const cachedEmoji = this.channel.messages.cache.get(emoji?.id ?? emoji); - if (cachedEmoji) return cachedEmoji; - - const reaction = this.reactions._add({ - emoji: Util.resolvePartialEmoji(emoji), - count: this.partial ? null : 0, - me: true, - }); - - reaction._add(this.client.user); - return reaction; + return this.client.actions.MessageReactionAdd.handle( + { + user: this.client.user, + channel: this.channel, + message: this, + emoji: Util.resolvePartialEmoji(emoji), + }, + true, + ).reaction; } /** From a9f0ccb67afc3a232cdb37b1d5799c10b6046b74 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 12 Oct 2021 23:57:07 +0100 Subject: [PATCH 9/9] chore: remove duplicate checks The `fromStructure` seems to be... better(?) --- src/client/actions/MessageReactionAdd.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client/actions/MessageReactionAdd.js b/src/client/actions/MessageReactionAdd.js index d6a01425cdf9..e5f5d1deb4c4 100644 --- a/src/client/actions/MessageReactionAdd.js +++ b/src/client/actions/MessageReactionAdd.js @@ -32,8 +32,6 @@ class MessageReactionAdd extends Action { // Verify reaction const includePartial = this.client.options.partials.includes(PartialTypes.REACTION); if (message.partial && !includePartial) return false; - const existing = message.reactions.cache.get(data.emoji.id ?? data.emoji.name); - if (existing?.users.cache.has(user.id)) return { message, reaction: existing, user }; const reaction = message.reactions._add({ emoji: data.emoji, count: message.partial ? null : 0, @@ -41,7 +39,7 @@ class MessageReactionAdd extends Action { }); if (!reaction) return false; reaction._add(user); - if (fromStructure && includePartial) return { message, reaction, user }; + if (fromStructure) return { message, reaction, user }; /** * Emitted whenever a reaction is added to a cached message. * @event Client#messageReactionAdd