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