mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
refactor(Collector): make endReason a getter (#5271)
This commit is contained in:
@@ -90,12 +90,7 @@ class MessageCollector extends Collector {
|
||||
return message.channel.id === this.channel.id ? message.id : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks after un/collection to see if the collector is done.
|
||||
* @returns {?string}
|
||||
* @private
|
||||
*/
|
||||
endReason() {
|
||||
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;
|
||||
|
||||
@@ -146,7 +146,7 @@ class ReactionCollector extends Collector {
|
||||
this.checkEnd();
|
||||
}
|
||||
|
||||
endReason() {
|
||||
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';
|
||||
if (this.options.maxUsers && this.users.size >= this.options.maxUsers) return 'userLimit';
|
||||
|
||||
@@ -214,7 +214,7 @@ class Collector extends EventEmitter {
|
||||
* Checks whether the collector should end, and if so, ends it.
|
||||
*/
|
||||
checkEnd() {
|
||||
const reason = this.endReason();
|
||||
const reason = this.endReason;
|
||||
if (reason) this.stop(reason);
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ class Collector extends EventEmitter {
|
||||
return Util.flatten(this);
|
||||
}
|
||||
|
||||
/* eslint-disable no-empty-function, valid-jsdoc */
|
||||
/* eslint-disable no-empty-function */
|
||||
/**
|
||||
* 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.
|
||||
@@ -273,14 +273,14 @@ class Collector extends EventEmitter {
|
||||
* @abstract
|
||||
*/
|
||||
dispose() {}
|
||||
/* eslint-enable no-empty-function */
|
||||
|
||||
/**
|
||||
* The reason this collector has ended or will end with.
|
||||
* @returns {?string} Reason to end the collector, if any
|
||||
* The reason this collector has ended with, or null if it hasn't ended yet
|
||||
* @name Collector#endReason
|
||||
* @type {?string}
|
||||
* @abstract
|
||||
*/
|
||||
endReason() {}
|
||||
/* eslint-enable no-empty-function, valid-jsdoc */
|
||||
}
|
||||
|
||||
module.exports = Collector;
|
||||
|
||||
Reference in New Issue
Block a user