From 9fbbf5bb2f9241740aef00b2aadfd6a5eb8779fe Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:06:51 +0800 Subject: [PATCH] [api/commands] Resupport `execute` return --- src/lib/api/commands/index.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/api/commands/index.ts b/src/lib/api/commands/index.ts index c63f2a4..bb84895 100644 --- a/src/lib/api/commands/index.ts +++ b/src/lib/api/commands/index.ts @@ -1,6 +1,7 @@ import { ApplicationCommand, ApplicationCommandInputType, ApplicationCommandType } from "@lib/api/commands/types"; -import { after } from "@lib/api/patcher"; -import { commands as commandsModule } from "@metro/common"; +import { after, instead } from "@lib/api/patcher"; +import { logger } from "@lib/utils/logger"; +import { commands as commandsModule, messageUtil } from "@metro/common"; let commands: ApplicationCommand[] = []; @@ -48,6 +49,18 @@ export function registerCommand(command: ApplicationCommand): () => void { opt.displayDescription ??= opt.description; } + instead("execute", command, (args, orig) => { + Promise.resolve( + orig.apply(command, args) + ).then(ret => { + if (ret && typeof ret === "object") { + messageUtil.sendMessage(args[1].channel.id, ret); + } + }).catch(err => { + logger.error("Failed to execute command", err); + }); + }); + // Add it to the commands array commands.push(command);