mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 01:31:29 +00:00
[wip] Fix collector documentation (again) (#1416)
* remove private on abstract methods, fix timeout type * make client readonly, add documentation to abstract methods * document implemented collector methods
This commit is contained in:
parent
89745fe132
commit
35c4c552f4
3 changed files with 41 additions and 6 deletions
|
|
@ -50,6 +50,12 @@ class MessageCollector extends Collector {
|
||||||
this.on('collect', this._reEmitter);
|
this.on('collect', this._reEmitter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming message for possible collection.
|
||||||
|
* @param {Message} message The message that could be collected.
|
||||||
|
* @returns {?{key: Snowflake, value: Message}} Message data to collect.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
handle(message) {
|
handle(message) {
|
||||||
if (message.channel.id !== this.channel.id) return null;
|
if (message.channel.id !== this.channel.id) return null;
|
||||||
this.received++;
|
this.received++;
|
||||||
|
|
@ -59,6 +65,11 @@ class MessageCollector extends Collector {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check after collection to see if the collector is done.
|
||||||
|
* @returns {?string} Reason to end the collector, if any.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
postCheck() {
|
postCheck() {
|
||||||
// Consider changing the end reasons for v12
|
// Consider changing the end reasons for v12
|
||||||
if (this.options.maxMatches && this.collected.size >= this.options.max) return 'matchesLimit';
|
if (this.options.maxMatches && this.collected.size >= this.options.max) return 'matchesLimit';
|
||||||
|
|
@ -66,6 +77,10 @@ class MessageCollector extends Collector {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes event listeners.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.removeListener('collect', this._reEmitter);
|
this.removeListener('collect', this._reEmitter);
|
||||||
this.client.removeListener('message', this.listener);
|
this.client.removeListener('message', this.listener);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ class ReactionCollector extends Collector {
|
||||||
this.client.on('messageReactionAdd', this.listener);
|
this.client.on('messageReactionAdd', this.listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming reaction for possible collection.
|
||||||
|
* @param {MessageReaction} reaction The reaction to possibly collect.
|
||||||
|
* @returns {?{key: Snowflake, value: MessageReaction}} Reaction data to collect.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
handle(reaction) {
|
handle(reaction) {
|
||||||
if (reaction.message.id !== this.message.id) return null;
|
if (reaction.message.id !== this.message.id) return null;
|
||||||
return {
|
return {
|
||||||
|
|
@ -51,6 +57,13 @@ class ReactionCollector extends Collector {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check after collection to see if the collector is done.
|
||||||
|
* @param {MessageReaction} reaction The reaction that was collected.
|
||||||
|
* @param {User} user The user that reacted.
|
||||||
|
* @returns {?string} Reason to end the collector, if any.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
postCheck(reaction, user) {
|
postCheck(reaction, user) {
|
||||||
this.users.set(user.id, user);
|
this.users.set(user.id, user);
|
||||||
if (this.options.max && ++this.total >= this.options.max) return 'limit';
|
if (this.options.max && ++this.total >= this.options.max) return 'limit';
|
||||||
|
|
@ -59,6 +72,10 @@ class ReactionCollector extends Collector {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove event listeners.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
cleanup() {
|
cleanup() {
|
||||||
this.client.removeListener('messageReactionAdd', this.listener);
|
this.client.removeListener('messageReactionAdd', this.listener);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,11 @@ class Collector extends EventEmitter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The client.
|
* The client.
|
||||||
|
* @name Collector#client
|
||||||
* @type {Client}
|
* @type {Client}
|
||||||
|
* @readonly
|
||||||
*/
|
*/
|
||||||
this.client = client;
|
Object.defineProperty(this, 'client', { value: client });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The filter applied to this collector.
|
* The filter applied to this collector.
|
||||||
|
|
@ -53,8 +55,8 @@ class Collector extends EventEmitter {
|
||||||
this.ended = false;
|
this.ended = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout ID for cleanup.
|
* Timeout for cleanup.
|
||||||
* @type {?number}
|
* @type {?Timeout}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._timeout = null;
|
this._timeout = null;
|
||||||
|
|
@ -148,25 +150,26 @@ class Collector extends EventEmitter {
|
||||||
|
|
||||||
/* eslint-disable no-empty-function, valid-jsdoc */
|
/* eslint-disable no-empty-function, valid-jsdoc */
|
||||||
/**
|
/**
|
||||||
|
* Handles incoming events from the `listener` function. Returns null if the
|
||||||
|
* event should not be collected, or returns an object describing the data that should be stored.
|
||||||
|
* @see Collector#listener
|
||||||
* @param {...*} args Any args the event listener emits.
|
* @param {...*} args Any args the event listener emits.
|
||||||
* @returns {?{key: string, value}} Data to insert into collection, if any.
|
* @returns {?{key: string, value}} Data to insert into collection, if any.
|
||||||
* @abstract
|
* @abstract
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
handle() {}
|
handle() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This method runs after collection to see if the collector should finish.
|
||||||
* @param {...*} args Any args the event listener emits.
|
* @param {...*} args Any args the event listener emits.
|
||||||
* @returns {?string} Reason to end the collector, if any.
|
* @returns {?string} Reason to end the collector, if any.
|
||||||
* @abstract
|
* @abstract
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
postCheck() {}
|
postCheck() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the collector is ending.
|
* Called when the collector is ending.
|
||||||
* @abstract
|
* @abstract
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
cleanup() {}
|
cleanup() {}
|
||||||
/* eslint-enable no-empty-function, valid-jsdoc */
|
/* eslint-enable no-empty-function, valid-jsdoc */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue