From 8e505ed349d39d7fbcc29f70fe96761f5ad6bb42 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Thu, 27 Oct 2016 16:30:02 +0100 Subject: [PATCH] Add Message Reaction me --- src/structures/Message.js | 22 +++++++++++++++++++++- src/structures/MessageReaction.js | 8 ++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/structures/Message.js b/src/structures/Message.js index 3c86f8821..da485713a 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -155,6 +155,13 @@ class Message { * @type {Collection} */ this.reactions = new Collection(); + + if (data.reactions && data.reactions.length > 0) { + for (const reaction of data.reactions) { + const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name; + this.reactions.set(id, new MessageReaction(this, reaction.emoji, reaction.count, reaction.me)); + } + } } _addReaction(emoji, user) { @@ -162,8 +169,9 @@ class Message { let reaction; if (this.reactions.has(emojiID)) { reaction = this.reactions.get(emojiID); + if (!reaction.me) reaction.me = user.id === this.client.user.id; } else { - reaction = new MessageReaction(this, emoji, 0); + reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id); this.reactions.set(emojiID, reaction); } if (!reaction.users.has(user.id)) { @@ -181,6 +189,9 @@ class Message { if (reaction.users.has(user.id)) { reaction.users.delete(user.id); reaction.count--; + if (user.id === this.client.user.id) { + reaction.me = false; + } return reaction; } } @@ -236,6 +247,15 @@ class Message { if (chan) this.mentions.channels.set(chan.id, chan); } } + if (data.reactions) { + this.reactions = new Collection(); + if (data.reactions.length > 0) { + for (const reaction of data.reactions) { + const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name; + this.reactions.set(id, new MessageReaction(this, data.emoji, data.count, data.me)); + } + } + } } /** diff --git a/src/structures/MessageReaction.js b/src/structures/MessageReaction.js index e7f06ab0d..77d6a1bd4 100644 --- a/src/structures/MessageReaction.js +++ b/src/structures/MessageReaction.js @@ -55,13 +55,17 @@ class ReactionEmoji { * Represents a reaction to a message */ class MessageReaction { - constructor(message, emoji, count) { + constructor(message, emoji, count, me) { /** * The message that this reaction refers to * @type {Message} */ this.message = message; - + /** + * Whether the client has given this reaction + * @type {boolean} + */ + this.me = me; this._emoji = new ReactionEmoji(this, emoji.name, emoji.id); /** * The number of people that have given the same reaction.