diff options
Diffstat (limited to 'node_modules/discord.js/src/client/actions/MessageReactionAdd.js')
-rw-r--r-- | node_modules/discord.js/src/client/actions/MessageReactionAdd.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/client/actions/MessageReactionAdd.js b/node_modules/discord.js/src/client/actions/MessageReactionAdd.js new file mode 100644 index 0000000..ea97bd6 --- /dev/null +++ b/node_modules/discord.js/src/client/actions/MessageReactionAdd.js @@ -0,0 +1,55 @@ +'use strict'; + +const Action = require('./Action'); +const Events = require('../../util/Events'); +const Partials = require('../../util/Partials'); + +/* +{ user_id: 'id', + message_id: 'id', + emoji: { name: '�', id: null }, + channel_id: 'id', + // If originating from a guild + guild_id: 'id', + member: { ..., user: { ... } } } +*/ + +class MessageReactionAdd extends Action { + handle(data, fromStructure = false) { + if (!data.emoji) return false; + + const user = this.getUserFromMember(data); + if (!user) return false; + + // Verify channel + const channel = this.getChannel(data); + if (!channel?.isTextBased()) return false; + + // Verify message + const message = this.getMessage(data, channel); + if (!message) return false; + + // Verify reaction + const includePartial = this.client.options.partials.includes(Partials.Reaction); + if (message.partial && !includePartial) return false; + const reaction = message.reactions._add({ + emoji: data.emoji, + count: message.partial ? null : 0, + me: user.id === this.client.user.id, + }); + if (!reaction) return false; + reaction._add(user); + if (fromStructure) return { message, reaction, user }; + /** + * Emitted whenever a reaction is added to a cached message. + * @event Client#messageReactionAdd + * @param {MessageReaction} messageReaction The reaction object + * @param {User} user The user that applied the guild or reaction emoji + */ + this.client.emit(Events.MessageReactionAdd, reaction, user); + + return { message, reaction, user }; + } +} + +module.exports = MessageReactionAdd; |