mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
feat(Collector): add lastCollectedTimestamp (#9044)
* feat(Collector): add lastCollectedTimestamp * docs: mark props as nullable Co-authored-by: Synbulat Biishev <syjalo.dev@gmail.com> * refactor: assign property in constructor --------- Co-authored-by: Synbulat Biishev <syjalo.dev@gmail.com> Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -95,6 +95,20 @@ class Collector extends EventEmitter {
|
||||
|
||||
if (options.time) this._timeout = setTimeout(() => this.stop('time'), options.time).unref();
|
||||
if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref();
|
||||
|
||||
/**
|
||||
* The timestamp at which this collector last collected an item
|
||||
* @type {?number}
|
||||
*/
|
||||
this.lastCollectedTimestamp = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Date at which this collector last collected an item
|
||||
* @type {?Date}
|
||||
*/
|
||||
get lastCollectedAt() {
|
||||
return this.lastCollectedTimestamp && new Date(this.lastCollectedTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,6 +132,7 @@ class Collector extends EventEmitter {
|
||||
*/
|
||||
this.emit('collect', ...args);
|
||||
|
||||
this.lastCollectedTimestamp = Date.now();
|
||||
if (this._idletimeout) {
|
||||
clearTimeout(this._idletimeout);
|
||||
this._idletimeout = setTimeout(() => this.stop('idle'), this.options.idle).unref();
|
||||
|
||||
Reference in New Issue
Block a user