fix: actually fix default props in components

This commit is contained in:
MARCROCK22 2024-06-06 17:36:29 +00:00
parent 9a942e8674
commit eef42a9a9f
3 changed files with 327 additions and 333 deletions

View File

@ -19,7 +19,7 @@ export abstract class ComponentCommand {
middlewares: (keyof RegisteredMiddlewares)[] = [];
props: ExtraProps = {};
props!: ExtraProps;
get cType(): number {
return ComponentType[this.componentType];

View File

@ -174,17 +174,11 @@ export class ComponentHandler extends BaseHandler {
}
if (!(component instanceof ModalCommand || component instanceof ComponentCommand)) continue;
component.props ??= this.client.options.commands?.defaults?.props ?? {};
if (component instanceof ModalCommand) {
component.onInternalError ??= this.client.options?.modals?.defaults?.onInternalError;
component.onMiddlewaresError ??= this.client.options?.modals?.defaults?.onMiddlewaresError;
component.onRunError ??= this.client.options?.modals?.defaults?.onRunError;
component.onAfterRun ??= this.client.options?.modals?.defaults?.onAfterRun;
} else {
component.onInternalError ??= this.client.options?.components?.defaults?.onInternalError;
component.onMiddlewaresError ??= this.client.options?.components?.defaults?.onMiddlewaresError;
component.onRunError ??= this.client.options?.components?.defaults?.onRunError;
component.onAfterRun ??= this.client.options?.components?.defaults?.onAfterRun;
}
const is = component instanceof ModalCommand ? 'modals' : 'components';
component.onInternalError ??= this.client.options?.[is]?.defaults?.onInternalError;
component.onMiddlewaresError ??= this.client.options?.[is]?.defaults?.onMiddlewaresError;
component.onRunError ??= this.client.options?.[is]?.defaults?.onRunError;
component.onAfterRun ??= this.client.options?.[is]?.defaults?.onAfterRun;
component.__filePath = value.path;
this.commands.push(component);
}

View File

@ -13,7 +13,7 @@ export abstract class ModalCommand {
middlewares: (keyof RegisteredMiddlewares)[] = [];
props: ExtraProps = {};
props!: ExtraProps;
onAfterRun?(context: ModalContext, error: unknown | undefined): any;
onRunError?(context: ModalContext, error: unknown): any;