docs(Collector): properly document endReason (#6016)

This commit is contained in:
SpaceEEC
2021-07-03 14:23:15 +02:00
committed by GitHub
parent 568691ce6a
commit 7dd1a8da08
5 changed files with 24 additions and 8 deletions

View File

@@ -89,6 +89,11 @@ class MessageCollector extends Collector {
return message.channel.id === this.channel.id ? message.id : null; 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() { get endReason() {
if (this.options.max && this.collected.size >= this.options.max) return 'limit'; if (this.options.max && this.collected.size >= this.options.max) return 'limit';
if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit'; if (this.options.maxProcessed && this.received === this.options.maxProcessed) return 'processedLimit';

View File

@@ -130,6 +130,11 @@ class MessageComponentInteractionCollector extends Collector {
this.checkEnd(); this.checkEnd();
} }
/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
*/
get endReason() { get endReason() {
if (this.options.max && this.total >= this.options.max) return 'limit'; 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.maxComponents && this.collected.size >= this.options.maxComponents) return 'componentLimit';

View File

@@ -145,6 +145,11 @@ class ReactionCollector extends Collector {
this.checkEnd(); this.checkEnd();
} }
/**
* The reason this collector has ended with, or null if it hasn't ended yet
* @type {?string}
* @readonly
*/
get endReason() { get endReason() {
if (this.options.max && this.total >= this.options.max) return 'limit'; 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.maxEmojis && this.collected.size >= this.options.maxEmojis) return 'emojiLimit';

View File

@@ -264,6 +264,14 @@ class Collector extends EventEmitter {
} }
/* eslint-disable no-empty-function */ /* 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 * 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. * be collected, or returns an object describing the data that should be stored.
@@ -284,13 +292,6 @@ class Collector extends EventEmitter {
*/ */
dispose() {} dispose() {}
/* eslint-enable no-empty-function */ /* 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; module.exports = Collector;

2
typings/index.d.ts vendored
View File

@@ -540,7 +540,7 @@ declare module 'discord.js' {
public readonly client: Client; public readonly client: Client;
public collected: Collection<K, V>; public collected: Collection<K, V>;
public ended: boolean; public ended: boolean;
public abstract endReason: string | null; public abstract readonly endReason: string | null;
public filter: CollectorFilter<[V, ...F]>; public filter: CollectorFilter<[V, ...F]>;
public readonly next: Promise<V>; public readonly next: Promise<V>;
public options: CollectorOptions<[V, ...F]>; public options: CollectorOptions<[V, ...F]>;