Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Collector): docs and types #5937

Merged
merged 1 commit into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/structures/MessageComponentInteractionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MessageComponentInteractionCollector extends Collector {
/**
* Handles an incoming interaction for possible collection.
* @param {Interaction} interaction The interaction to possibly collect
* @returns {?(Snowflake|string)}
* @returns {?Snowflake}
* @private
*/
collect(interaction) {
Expand Down
2 changes: 1 addition & 1 deletion src/structures/ReactionCollector.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ReactionCollector extends Collector {
* Handles an incoming reaction for possible collection.
* @param {MessageReaction} reaction The reaction to possibly collect
* @param {User} user The user that added the reaction
* @returns {Promise<Snowflake|string>}
* @returns {Promise<?(Snowflake|string)>}
* @private
*/
async collect(reaction, user) {
Expand Down
4 changes: 2 additions & 2 deletions src/structures/interfaces/Collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Collector extends EventEmitter {
* @emits Collector#collect
*/
async handleCollect(...args) {
const collect = this.collect(...args);
const collect = await this.collect(...args);

if (collect && (await this.filter(...args, this.collected))) {
this.collected.set(collect, args[0]);
Expand Down Expand Up @@ -269,7 +269,7 @@ class Collector extends EventEmitter {
* be collected, or returns an object describing the data that should be stored.
* @see Collector#handleCollect
* @param {...*} args Any args the event listener emits
* @returns {?{key, value}} Data to insert into collection, if any
* @returns {?(*|Promise<?*>)} Data to insert into collection, if any
* @abstract
*/
collect() {}
Expand Down
26 changes: 13 additions & 13 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,18 @@ declare module 'discord.js' {
public adapters: Map<Snowflake, DiscordGatewayAdapterLibraryMethods>;
}

export abstract class Collector<K, V> extends EventEmitter {
constructor(client: Client, options?: CollectorOptions<[V]>);
export abstract class Collector<K, V, F extends any[] = []> extends EventEmitter {
constructor(client: Client, options?: CollectorOptions<[V, ...F]>);
private _timeout: NodeJS.Timeout | null;
private _idletimeout: NodeJS.Timeout | null;

public readonly client: Client;
public collected: Collection<K, V>;
public ended: boolean;
public abstract endReason: string | null;
public filter: CollectorFilter<[V]>;
public filter: CollectorFilter<[V, ...F]>;
public readonly next: Promise<V>;
public options: CollectorOptions<[V]>;
public options: CollectorOptions<[V, ...F]>;
public checkEnd(): void;
public handleCollect(...args: any[]): Promise<void>;
public handleDispose(...args: any[]): Promise<void>;
Expand All @@ -501,8 +501,8 @@ declare module 'discord.js' {
public toJSON(): unknown;

protected listener: (...args: any[]) => void;
public abstract collect(...args: any[]): K;
public abstract dispose(...args: any[]): K;
public abstract collect(...args: any[]): K | null | Promise<K | null>;
public abstract dispose(...args: any[]): K | null;

public on(event: 'collect' | 'dispose', listener: (...args: any[]) => Awaited<void>): this;
public on(event: 'end', listener: (collected: Collection<K, V>, reason: string) => Awaited<void>): this;
Expand Down Expand Up @@ -1366,8 +1366,8 @@ declare module 'discord.js' {
public options: MessageCollectorOptions;
public received: number;

public collect(message: Message): Snowflake;
public dispose(message: Message): Snowflake;
public collect(message: Message): Snowflake | null;
public dispose(message: Message): Snowflake | null;
}

export class MessageComponentInteraction extends Interaction {
Expand Down Expand Up @@ -1408,8 +1408,8 @@ declare module 'discord.js' {
public total: number;
public users: Collection<Snowflake, User>;

public collect(interaction: Interaction): Snowflake;
public dispose(interaction: Interaction): Snowflake;
public collect(interaction: Interaction): Snowflake | null;
public dispose(interaction: Interaction): Snowflake | null;
public on(
event: 'collect' | 'dispose',
listener: (interaction: MessageComponentInteraction) => Awaited<void>,
Expand Down Expand Up @@ -1616,7 +1616,7 @@ declare module 'discord.js' {
public equals(presence: Presence): boolean;
}

export class ReactionCollector extends Collector<Snowflake | string, MessageReaction> {
export class ReactionCollector extends Collector<Snowflake | string, MessageReaction, [User]> {
constructor(message: Message, options?: ReactionCollectorOptions);
private _handleChannelDeletion(channel: GuildChannel): void;
private _handleGuildDeletion(guild: Guild): void;
Expand All @@ -1630,8 +1630,8 @@ declare module 'discord.js' {

public static key(reaction: MessageReaction): Snowflake | string;

public collect(reaction: MessageReaction): Promise<Snowflake | string>;
public dispose(reaction: MessageReaction, user: User): Snowflake | string;
public collect(reaction: MessageReaction, user: User): Promise<Snowflake | string | null>;
public dispose(reaction: MessageReaction, user: User): Snowflake | string | null;
public empty(): void;

public on(event: 'collect' | 'dispose' | 'remove', listener: (reaction: MessageReaction, user: User) => void): this;
Expand Down