mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
fix: reload commands
This commit is contained in:
parent
9c42027676
commit
28fb9b8cda
@ -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>): any;
|
||||
|
@ -36,12 +36,17 @@ export class CommandHandler extends BaseHandler {
|
||||
}
|
||||
|
||||
async load(commandsDir: string, client: UsingClient) {
|
||||
const result = (await this.loadFilesK<typeof Command>(await this.getFiles(commandsDir))).filter(x => x.file);
|
||||
const result = (
|
||||
await this.loadFilesK<typeof Command | typeof SubCommand | typeof ContextMenuCommand>(
|
||||
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 {
|
||||
|
@ -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('\\\\'));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user