mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
refactor: update customId matching logic and rename asyncRun to waitFor
This commit is contained in:
parent
b84d462ce2
commit
e810b6eb52
@ -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);
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user