fix(ReactionCollector): only modify users and total on collect (#3905)

This commit is contained in:
SpaceEEC
2020-03-08 19:33:18 +01:00
committed by GitHub
parent d72172744e
commit 20075e306b
2 changed files with 15 additions and 3 deletions

View File

@@ -41,6 +41,11 @@ class ReactionCollector extends Collector {
if (this.client.getMaxListeners() !== 0) this.client.setMaxListeners(this.client.getMaxListeners() + 1);
this.client.on('messageReactionAdd', this.listener);
this.on('fullCollect', (reaction, user) => {
this.users.set(user.id, user);
this.total++;
});
}
/**
@@ -64,9 +69,8 @@ class ReactionCollector extends Collector {
* @returns {?string} Reason to end the collector, if any
* @private
*/
postCheck(reaction, user) {
this.users.set(user.id, user);
if (this.options.max && ++this.total >= this.options.max) return 'limit';
postCheck() {
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';
return null;

View File

@@ -99,6 +99,14 @@ class Collector extends EventEmitter {
*/
this.emit('collect', collect.value, this);
/**
* Emitted whenever an element is collected.
* @event Collector#fullCollect
* @param {...*} args The arguments emitted by the listener
* @private
*/
this.emit('fullCollect', ...args, this);
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), this.options.idle);