refactor: update customId matching logic and rename asyncRun to waitFor

This commit is contained in:
MARCROCK22 2025-06-14 19:24:53 -04:00
parent b84d462ce2
commit e810b6eb52
2 changed files with 4 additions and 5 deletions

View File

@ -21,9 +21,8 @@ export abstract class ComponentCommand {
/** @internal */ /** @internal */
_filter(context: ComponentContext) { _filter(context: ComponentContext) {
if (this.customId) { if (this.customId) {
const isString = typeof this.customId === 'string'; const matches =
const matches = isString ? this.customId === context.customId : (this.customId as RegExp).test(context.customId); typeof this.customId === 'string' ? this.customId === context.customId : context.customId.match(this.customId);
if (!matches) return false; if (!matches) return false;
} }
if (this.filter) return this.filter(context); if (this.filter) return this.filter(context);

View File

@ -38,7 +38,7 @@ export interface CreateComponentCollectorResult {
callback: ComponentCallback<T>, callback: ComponentCallback<T>,
): void; ): void;
stop(reason?: string): void; stop(reason?: string): void;
asyncRun<T extends CollectorInteraction = CollectorInteraction>(customId: UserMatches): Promise<T | null>; waitFor<T extends CollectorInteraction = CollectorInteraction>(customId: UserMatches): Promise<T | null>;
resetTimeouts(): void; resetTimeouts(): void;
} }
@ -117,7 +117,7 @@ export class ComponentHandler extends BaseHandler {
this.createComponentCollector(messageId, channelId, guildId, options, old.components); this.createComponentCollector(messageId, channelId, guildId, options, old.components);
}); });
}, },
asyncRun: customId => waitFor: customId =>
new Promise(resolve => { new Promise(resolve => {
const collector = this.values.get(messageId); const collector = this.values.get(messageId);
if (!collector) return resolve(null); if (!collector) return resolve(null);