Skip to content

Commit

Permalink
docs(Collector): properly document endReason (#6016)
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Jul 3, 2021
1 parent 568691c commit 7dd1a8d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/structures/MessageCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ class MessageCollector extends Collector {
return message.channel.id === this.channel.id ? message.id : null;
}

/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
*/
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';
Expand Down
5 changes: 5 additions & 0 deletions src/structures/MessageComponentInteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class MessageComponentInteractionCollector extends Collector {
this.checkEnd();
}

/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
*/
get endReason() {
if (this.options.max && this.total >= this.options.max) return 'limit';
if (this.options.maxComponents && this.collected.size >= this.options.maxComponents) return 'componentLimit';
Expand Down
5 changes: 5 additions & 0 deletions src/structures/ReactionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class ReactionCollector extends Collector {
this.checkEnd();
}

/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
*/
get endReason() {
if (this.options.max && this.total >= this.options.max) return 'limit';
if (this.options.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit';
Expand Down
15 changes: 8 additions & 7 deletions src/structures/interfaces/Collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ class Collector extends EventEmitter {
}

/* eslint-disable no-empty-function */
/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
* @abstract
*/
get endReason() {}

/**
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
* be collected, or returns an object describing the data that should be stored.
Expand All @@ -284,13 +292,6 @@ class Collector extends EventEmitter {
*/
dispose() {}
/* eslint-enable no-empty-function */

/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @name Collector#endReason
* @type {?string}
* @abstract
*/
}

module.exports = Collector;
2 changes: 1 addition & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ declare module 'discord.js' {
public readonly client: Client;
public collected: Collection<K, V>;
public ended: boolean;
public abstract endReason: string | null;
public abstract readonly endReason: string | null;
public filter: CollectorFilter<[V, ...F]>;
public readonly next: Promise<V>;
public options: CollectorOptions<[V, ...F]>;
Expand Down

0 comments on commit 7dd1a8d

Please sign in to comment.