Skip to content

Commit

Permalink
feat(Collector): add lastCollectedTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Jan 11, 2023
1 parent 8dfd003 commit 4309d4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/discord.js/src/structures/interfaces/Collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ class Collector extends EventEmitter {
if (options.idle) this._idletimeout = setTimeout(() => this.stop('idle'), options.idle).unref();
}

/**
* The timestamp at which this collector last collected an item
* @type {number|null}
*/
lastCollectedTimestamp = null;

/**
* The Date at which this collector last collected an item
* @type {Date|null}
*/
get lastCollectedAt() {
return this.lastCollectedTimestamp && new Date(this.lastCollectedTimestamp);
}

/**
* Call this to handle an event as a collectable element. Accepts any event data as parameters.
* @param {...*} args The arguments emitted by the listener
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,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]>;
Expand Down

0 comments on commit 4309d4d

Please sign in to comment.