mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 12:36:08 +00:00
feat: use regex in customId component command
This commit is contained in:
parent
61413181bb
commit
8472917a7c
@ -14,13 +14,18 @@ export interface ComponentCommand {
|
||||
export abstract class ComponentCommand {
|
||||
type = InteractionCommandType.COMPONENT;
|
||||
abstract componentType: keyof ContextComponentCommandInteractionMap;
|
||||
customId?: string;
|
||||
customId?: string | RegExp;
|
||||
filter?(context: ComponentContext<typeof this.componentType>): Promise<boolean> | boolean;
|
||||
abstract run(context: ComponentContext<typeof this.componentType>): any;
|
||||
|
||||
/** @internal */
|
||||
_filter(context: ComponentContext) {
|
||||
if (this.customId && this.customId !== context.customId) return false;
|
||||
if (this.customId) {
|
||||
const isString = typeof this.customId === 'string';
|
||||
const matches = isString ? this.customId === context.customId : (this.customId as RegExp).test(context.customId);
|
||||
|
||||
if (!matches) return false;
|
||||
}
|
||||
if (this.filter) return this.filter(context);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user