Fix ReactionCollector#remove and make Collector interface more consistent (#2221)

* Fix ReactionCollector#remove and make Collector interface more consistent

* Move those below the doc

* Remove object spread

* Only emit event arguments

* Forgot to delete this line

* Update docs

* Also fix this

* More edits to docs

* Snowflake|string
This commit is contained in:
Alex
2018-01-16 02:33:58 +02:00
committed by Crawl
parent 36555c1cea
commit e576387fea
3 changed files with 41 additions and 25 deletions

View File

@@ -52,12 +52,12 @@ class ReactionCollector extends Collector {
this.client.removeListener(Events.MESSAGE_REACTION_REMOVE_ALL, this.empty);
});
this.on('collect', (collected, reaction, user) => {
this.on('collect', (reaction, user) => {
this.total++;
this.users.set(user.id, user);
});
this.on('dispose', (disposed, reaction, user) => {
this.on('remove', (reaction, user) => {
this.total--;
if (!this.collected.some(r => r.users.has(user.id))) this.users.delete(user.id);
});
@@ -66,23 +66,33 @@ class ReactionCollector extends Collector {
/**
* Handles an incoming reaction for possible collection.
* @param {MessageReaction} reaction The reaction to possibly collect
* @returns {?{key: Snowflake, value: MessageReaction}}
* @returns {?Snowflake|string}
* @private
*/
collect(reaction) {
/**
* Emitted whenever a reaction is collected.
* @event ReactionCollector#collect
* @param {MessageReaction} reaction The reaction that was collected
* @param {User} user The user that added the reaction
*/
if (reaction.message.id !== this.message.id) return null;
return {
key: ReactionCollector.key(reaction),
value: reaction,
};
return ReactionCollector.key(reaction);
}
/**
* Handles a reaction deletion for possible disposal.
* @param {MessageReaction} reaction The reaction to possibly dispose
* @param {MessageReaction} reaction The reaction to possibly dispose of
* @param {User} user The user that removed the reaction
* @returns {?Snowflake|string}
*/
dispose(reaction) {
dispose(reaction, user) {
/**
* Emitted whenever a reaction is disposed of.
* @event ReactionCollector#dispose
* @param {MessageReaction} reaction The reaction that was disposed of
* @param {User} user The user that removed the reaction
*/
if (reaction.message.id !== this.message.id) return null;
/**
@@ -91,8 +101,11 @@ class ReactionCollector extends Collector {
* is removed.
* @event ReactionCollector#remove
* @param {MessageReaction} reaction The reaction that was removed
* @param {User} user The user that removed the reaction
*/
if (this.collected.has(reaction)) this.emit('remove', reaction);
if (this.collected.has(ReactionCollector.key(reaction))) {
this.emit('remove', reaction, user);
}
return reaction.count ? null : ReactionCollector.key(reaction);
}