feat(Collector): Addition of resetTimer() (#3825)

* feat(Collector): Addition of resetTimer()

* typings
This commit is contained in:
matthewfripp
2020-02-24 17:17:24 +00:00
committed by GitHub
parent a69ebbe9d9
commit acf724e691
2 changed files with 18 additions and 0 deletions

View File

@@ -188,6 +188,23 @@ class Collector extends EventEmitter {
this.emit('end', this.collected, reason);
}
/**
* Resets the collectors timeout and idle timer.
* @param {Object} [options] Options
* @param {number} [options.time] How long to run the collector for in milliseconds
* @param {number} [options.idle] How long to stop the collector after inactivity in milliseconds
*/
resetTimer({ time, idle } = {}) {
if (this._timeout) {
this.client.clearTimeout(this._timeout);
this._timeout = this.client.setTimeout(() => this.stop('time'), time || this.options.time);
}
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), idle || this.options.idle);
}
}
/**
* Checks whether the collector should end, and if so, ends it.
*/

1
typings/index.d.ts vendored
View File

@@ -337,6 +337,7 @@ declare module 'discord.js' {
public handleCollect(...args: any[]): void;
public handleDispose(...args: any[]): void;
public stop(reason?: string): void;
public resetTimer(options?: { time?: number, idle?: number }): void;
public [Symbol.asyncIterator](): AsyncIterableIterator<V>;
public toJSON(): object;