Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ReactionCollector): only call the filter function once #6734

Merged
merged 2 commits into from Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
iCrawl marked this conversation as resolved.
Show resolved Hide resolved
* @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 @@ -1572,7 +1572,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