Skip to content

Commit

Permalink
fix: endReason not being properly set in base Collector (#7833)
Browse files Browse the repository at this point in the history
* fix: `endReason` not being properly set in base Collector

* types: add _endReason type
  • Loading branch information
KhafraDev committed Apr 25, 2022
1 parent ece6289 commit 0c18dab
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/InteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class InteractionCollector extends Collector {
if (this.options.max && this.total >= this.options.max) return 'limit';
if (this.options.maxComponents && this.collected.size >= this.options.maxComponents) return 'componentLimit';
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
return null;
return super.endReason;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/MessageCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class MessageCollector extends Collector {
get endReason() {
if (this.options.max && this.collected.size >= this.options.max) return 'limit';
if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit';
return null;
return super.endReason;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/ReactionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class ReactionCollector extends Collector {
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;
return super.endReason;
}

/**
Expand Down
14 changes: 12 additions & 2 deletions packages/discord.js/src/structures/interfaces/Collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ class Collector extends EventEmitter {
*/
this._idletimeout = null;

/**
* The reason the collector ended
* @type {string|null}
* @private
*/
this._endReason = null;

if (typeof this.filter !== 'function') {
throw new TypeError('INVALID_TYPE', 'options.filter', 'function');
}
Expand Down Expand Up @@ -187,6 +194,8 @@ class Collector extends EventEmitter {
clearTimeout(this._idletimeout);
this._idletimeout = null;
}

this._endReason = reason;
this.ended = true;

/**
Expand Down Expand Up @@ -270,9 +279,10 @@ class Collector extends EventEmitter {
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
* @abstract
*/
get endReason() {}
get endReason() {
return this._endReason;
}

/**
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
Expand Down
6 changes: 2 additions & 4 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -875,11 +875,12 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
protected constructor(client: Client, options?: CollectorOptions<[V, ...F]>);
private _timeout: NodeJS.Timeout | null;
private _idletimeout: NodeJS.Timeout | null;
private _endReason: string | null;

public readonly client: Client;
public collected: Collection<K, V>;
public ended: boolean;
public abstract get endReason(): string | null;
public get endReason(): string | null;
public filter: CollectorFilter<[V, ...F]>;
public get next(): Promise<V>;
public options: CollectorOptions<[V, ...F]>;
Expand Down Expand Up @@ -1552,7 +1553,6 @@ export class InteractionCollector<T extends Interaction> extends Collector<Snowf
public channelId: Snowflake | null;
public messageInteractionId: Snowflake | null;
public componentType: ComponentType | null;
public get endReason(): string | null;
public guildId: Snowflake | null;
public interactionType: InteractionType | null;
public messageId: Snowflake | null;
Expand Down Expand Up @@ -1767,7 +1767,6 @@ export class MessageCollector extends Collector<Snowflake, Message, [Collection<
private _handleGuildDeletion(guild: Guild): void;

public channel: TextBasedChannel;
public get endReason(): string | null;
public options: MessageCollectorOptions;
public received: number;

Expand Down Expand Up @@ -2016,7 +2015,6 @@ export class ReactionCollector extends Collector<Snowflake | string, MessageReac
private _handleGuildDeletion(guild: Guild): void;
private _handleMessageDeletion(message: Message): void;

public get endReason(): string | null;
public message: Message;
public options: ReactionCollectorOptions;
public total: number;
Expand Down

0 comments on commit 0c18dab

Please sign in to comment.