refactor(Collector): make filter an option (#5903)

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
Jan
2021-06-26 11:57:06 +02:00
committed by GitHub
parent 1439183ad3
commit 0d0c8f07f2
7 changed files with 61 additions and 83 deletions

View File

@@ -20,11 +20,10 @@ const { Events } = require('../util/Constants');
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);
constructor(message, options = {}) {
super(message.client, options);
/**
* The message upon which to collect reactions
@@ -82,10 +81,10 @@ class ReactionCollector extends Collector {
* Handles an incoming reaction for possible collection.
* @param {MessageReaction} reaction The reaction to possibly collect
* @param {User} user The user that added the reaction
* @returns {?(Snowflake|string)}
* @returns {Promise<Snowflake|string>}
* @private
*/
collect(reaction, user) {
async collect(reaction, user) {
/**
* Emitted whenever a reaction is collected.
* @event ReactionCollector#collect
@@ -102,7 +101,7 @@ class ReactionCollector extends Collector {
* @param {MessageReaction} reaction The reaction that was added
* @param {User} user The user that added the reaction
*/
if (reaction.count === 1 && this.filter(reaction, user, this.collected)) {
if (reaction.count === 1 && (await this.filter(reaction, user, this.collected))) {
this.emit('create', reaction, user);
}