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 */
_filter(context: ComponentContext) {
if (this.customId) {
const isString = typeof this.customId === 'string';
const matches = isString ? this.customId === context.customId : (this.customId as RegExp).test(context.customId);
const matches =
typeof this.customId === 'string' ? this.customId === context.customId : context.customId.match(this.customId);
if (!matches) return false;
}
if (this.filter) return this.filter(context);

View File

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