mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-30 23:50:07 +00:00
* message reaction collectors * docs cleanup * abstraction * remove pointless method * rename reaction collector creator method * docs and stuff * fix docs & build * backwards compatibility, fix docs * fix docs * remove deprecated comments * betterer docs again * Fix documentation * Fix Alias to not break depreciated code
65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
const Collector = require('./interfaces/Collector');
|
|
const Collection = require('../util/Collection');
|
|
|
|
/**
|
|
* @typedef {CollectorOptions} ReactionCollectorOptions
|
|
* @property {number} max The maximum total amount of reactions to collect.
|
|
* @property {number} maxEmojis The maximum number of emojis to collect.
|
|
* @property {number} maxUsers The maximum number of users to react.
|
|
*/
|
|
|
|
/**
|
|
* Collects reactions on messages.
|
|
* @implements {Collector}
|
|
*/
|
|
class ReactionCollector extends Collector {
|
|
|
|
/**
|
|
* @param {Message} message The message upon which to collect reactions.
|
|
* @param {CollectorFilter} filter The filter to apply to this collector.
|
|
* @param {ReactionCollectorOptions} [options={}] The options to apply to this collector.
|
|
*/
|
|
constructor(message, filter, options = {}) {
|
|
super(message.client, filter, options);
|
|
|
|
/**
|
|
* @type {Message} message The message.
|
|
*/
|
|
this.message = message;
|
|
|
|
/**
|
|
* @type {Collection} users Users which have reacted.
|
|
*/
|
|
this.users = new Collection();
|
|
|
|
/**
|
|
* @type {number} total Total number of reactions collected.
|
|
*/
|
|
this.total = 0;
|
|
|
|
this.client.on('messageReactionAdd', this.listener);
|
|
}
|
|
|
|
handle(reaction) {
|
|
if (reaction.message.id !== this.message.id) return null;
|
|
return {
|
|
key: reaction.emoji.id || reaction.emoji.name,
|
|
value: reaction,
|
|
};
|
|
}
|
|
|
|
postCheck(reaction, user) {
|
|
this.users.set(user.id, user);
|
|
if (this.options.max && ++this.total >= this.options.max) return 'limit';
|
|
if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit';
|
|
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
|
return null;
|
|
}
|
|
|
|
cleanup() {
|
|
this.client.removeListener('messageReactionAdd', this.listener);
|
|
}
|
|
}
|
|
|
|
module.exports = ReactionCollector;
|