Add message reaction collectors & abstract collectors (#1335)

* 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
This commit is contained in:
Will Nelson
2017-04-19 09:52:40 -07:00
committed by Crawl
parent 8475a4abee
commit ca34c43ba0
10 changed files with 345 additions and 135 deletions

View File

@@ -2,6 +2,7 @@ const Mentions = require('./MessageMentions');
const Attachment = require('./MessageAttachment');
const Embed = require('./MessageEmbed');
const MessageReaction = require('./MessageReaction');
const ReactionCollector = require('./ReactionCollector');
const Util = require('../util/Util');
const Collection = require('../util/Collection');
const Constants = require('../util/Constants');
@@ -245,6 +246,47 @@ class Message {
});
}
/**
* Creates a reaction collector.
* @param {CollectorFilter} filter The filter to apply.
* @param {ReactionCollectorOptions} [options={}] Options to send to the collector.
* @returns {ReactionCollector}
* @example
* // create a reaction collector
* const collector = message.createReactionCollector(
* (reaction, user) => reaction.emoji.id === '👌' && user.id === 'someID',
* { time: 15000 }
* );
* collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
* collector.on('end', collected => console.log(`Collected ${collected.size} items`));
*/
createReactionCollector(filter, options = {}) {
return new ReactionCollector(this, filter, options);
}
/**
* An object containing the same properties as CollectorOptions, but a few more:
* @typedef {ReactionCollectorOptions} AwaitReactionsOptions
* @property {string[]} [errors] Stop/end reasons that cause the promise to reject
*/
/**
* Similar to createCollector but in promise form. Resolves with a collection of reactions that pass the specified
* filter.
* @param {CollectorFilter} filter The filter function to use
* @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
* @returns {Promise<Collection<string, MessageReaction>>}
*/
awaitReactions(filter, options = {}) {
return new Promise((resolve, reject) => {
const collector = this.createReactionCollector(filter, options);
collector.once('end', (reactions, reason) => {
if (options.errors && options.errors.includes(reason)) reject(reactions);
else resolve(reactions);
});
});
}
/**
* An array of cached versions of the message, including the current version.
* Sorted from latest (first) to oldest (last).