Skip to content

Commit

Permalink
fix(ReactionCollector): only call the filter function once (#6734)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Oct 3, 2021
1 parent 905d100 commit d15dd5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
27 changes: 13 additions & 14 deletions src/structures/ReactionCollector.js
Expand Up @@ -67,6 +67,17 @@ class ReactionCollector extends Collector {
});

this.on('collect', (reaction, user) => {
/**
* Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is
* added to the message, as opposed to {@link Collector#collect} which which will
* be emitted even when a reaction has already been added to the message.
* @event ReactionCollector#create
* @param {MessageReaction} reaction The reaction that was added
* @param {User} user The user that added the reaction
*/
if (reaction.count === 1) {
this.emit('create', reaction, user);
}
this.total++;
this.users.set(user.id, user);
});
Expand All @@ -81,10 +92,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 {Promise<?(Snowflake|string)>}
* @returns {?(Snowflake|string)}
* @private
*/
async collect(reaction, user) {
collect(reaction) {
/**
* Emitted whenever a reaction is collected.
* @event ReactionCollector#collect
Expand All @@ -93,18 +104,6 @@ class ReactionCollector extends Collector {
*/
if (reaction.message.id !== this.message.id) return null;

/**
* Emitted whenever a reaction is newly created on a message. Will emit only when a new reaction is
* added to the message, as opposed to {@link Collector#collect} which which will
* be emitted even when a reaction has already been added to the message.
* @event ReactionCollector#create
* @param {MessageReaction} reaction The reaction that was added
* @param {User} user The user that added the reaction
*/
if (reaction.count === 1 && (await this.filter(reaction, user, this.collected))) {
this.emit('create', reaction, user);
}

return ReactionCollector.key(reaction);
}

Expand Down
2 changes: 1 addition & 1 deletion typings/index.d.ts
Expand Up @@ -1598,7 +1598,7 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac

public static key(reaction: MessageReaction): Snowflake | string;

public collect(reaction: MessageReaction, user: User): Promise<Snowflake | string | null>;
public collect(reaction: MessageReaction, user: User): Snowflake | string | null;
public dispose(reaction: MessageReaction, user: User): Snowflake | string | null;
public empty(): void;

Expand Down

0 comments on commit d15dd5f

Please sign in to comment.