mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13: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();
|
||||
|
||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -1060,6 +1060,8 @@ export abstract class Collector<K, V, F extends unknown[] = []> extends EventEmi
|
||||
|
||||
public readonly client: Client;
|
||||
public collected: Collection<K, V>;
|
||||
public lastCollectedTimestamp: number | null;
|
||||
public get lastCollectedAt(): Date | null;
|
||||
public ended: boolean;
|
||||
public get endReason(): string | null;
|
||||
public filter: CollectorFilter<[V, ...F]>;
|
||||
|
||||
Reference in New Issue
Block a user