Add maxMatches CollectorOption

This commit is contained in:
Schuyler Cebulskie
2016-10-18 21:23:35 -04:00
parent 9c8eb2dfc3
commit d0463926c4

View File

@@ -24,6 +24,7 @@ class MessageCollector extends EventEmitter {
* @typedef {Object} CollectorOptions
* @property {number} [time] Duration for the collector in milliseconds
* @property {number} [max] Maximum number of messages to handle
* @property {number} [maxMatches] Maximum number of successfully filtered messages to obtain
*/
/**
@@ -86,7 +87,8 @@ class MessageCollector extends EventEmitter {
* @event MessageCollector#message
*/
this.emit('message', message, this);
if (this.options.max && this.collected.size === this.options.max) this.stop('limit');
if (this.collected.size >= this.options.maxMatches) this.stop('matchesLimit');
else if (this.options.max && this.collected.size === this.options.max) this.stop('limit');
return true;
}
return false;