fix: endReason not being properly set in base Collector (#7833)

* fix: `endReason` not being properly set in base Collector

* types: add _endReason type
This commit is contained in:
Khafra
2022-04-25 18:31:12 -04:00
committed by GitHub
parent ece628986c
commit 0c18dab128
5 changed files with 17 additions and 9 deletions

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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');
}
@@ -187,6 +194,8 @@ class Collector extends EventEmitter {
clearTimeout(this._idletimeout);
this._idletimeout = null;
}
this._endReason = reason;
this.ended = true;
/**
@@ -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

View File

@@ -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]>;
@@ -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;
@@ -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;
@@ -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;