diff --git a/src/commands/applications/chat.ts b/src/commands/applications/chat.ts index 1224928..729b85c 100644 --- a/src/commands/applications/chat.ts +++ b/src/commands/applications/chat.ts @@ -271,6 +271,12 @@ class BaseCommand { const __tempCommand = await magicImport(this.__filePath!).then(x => x.default ?? x); Object.setPrototypeOf(this, __tempCommand.prototype); + + for (const i of this.options ?? []) { + if (i instanceof SubCommand && i.__filePath) { + await i.reload(); + } + } } run?(context: CommandContext): any; diff --git a/src/commands/handler.ts b/src/commands/handler.ts index 1f8674b..2a35a12 100644 --- a/src/commands/handler.ts +++ b/src/commands/handler.ts @@ -36,12 +36,17 @@ export class CommandHandler extends BaseHandler { } async load(commandsDir: string, client: UsingClient) { - const result = (await this.loadFilesK(await this.getFiles(commandsDir))).filter(x => x.file); + const result = ( + await this.loadFilesK( + await this.getFiles(commandsDir), + ) + ).filter(x => x.file); this.values = []; for (const command of result) { let commandInstance; try { + //@ts-expect-error abstract class commandInstance = new command.file(); } catch (e) { if (e instanceof Error && e.message === 'command.file is not a constructor') { @@ -72,8 +77,10 @@ export class CommandHandler extends BaseHandler { continue; } try { + //@ts-expect-error abstract class const subCommand = new (result.find(x => x.path === option)!.file)(); if (subCommand instanceof SubCommand) { + subCommand.__filePath = option; commandInstance.options.push(subCommand); } } catch { diff --git a/src/common/it/utils.ts b/src/common/it/utils.ts index ed57b7b..ab526f0 100644 --- a/src/common/it/utils.ts +++ b/src/common/it/utils.ts @@ -251,7 +251,7 @@ export async function magicImport(path: string) { return require(path); } catch { // biome-ignore lint/security/noGlobalEval: modules import broke - return eval('((path) => import(`file:///${path}`))')(path.split('\\').join('\\\\')); + return eval('((path) => import(`file:///${path}?update=${Date.now()}`))')(path.split('\\').join('\\\\')); } }