From 0df438fea87559bfd36459b4c6ac84d91a8926eb Mon Sep 17 00:00:00 2001 From: Sam Huynh Date: Sun, 14 Apr 2024 08:10:58 +1000 Subject: [PATCH] refactor: make deployCommands function only take 1 single commands param --- bin/main.ts | 2 +- scripts/delete-global-commands.ts | 2 +- scripts/delete-guild-commands.ts | 2 +- scripts/deploy-guild-commands.ts | 2 +- src/commands/deploy-command.ts | 12 ++++-------- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/bin/main.ts b/bin/main.ts index 2bbbf360..a21ced83 100644 --- a/bin/main.ts +++ b/bin/main.ts @@ -22,7 +22,7 @@ const main = async () => { // For development usage, please use `pnpm deploy:command` logger.info('[main]: Deploying global commands'); const op = await Result.safe( - deployGlobalCommands(commandList, contextMenuCommandList, { + deployGlobalCommands([...commandList, ...contextMenuCommandList], { token, clientId: client.user.id, }) diff --git a/scripts/delete-global-commands.ts b/scripts/delete-global-commands.ts index 064e527d..c2c38bc8 100644 --- a/scripts/delete-global-commands.ts +++ b/scripts/delete-global-commands.ts @@ -10,7 +10,7 @@ const deploy = async () => { logger.info('[delete-global-commands]: Deleting global commands'); const op = await Result.safe( - deployGlobalCommands([], [], { + deployGlobalCommands([], { token, clientId, }) diff --git a/scripts/delete-guild-commands.ts b/scripts/delete-guild-commands.ts index ef004502..33b2814e 100644 --- a/scripts/delete-guild-commands.ts +++ b/scripts/delete-guild-commands.ts @@ -16,7 +16,7 @@ const deploy = async () => { logger.info('[delete-guild-commands]: Deleting guild commands'); const op = await Result.safe( - deployGuildCommands([], [], { + deployGuildCommands([], { token, clientId, guildId, diff --git a/scripts/deploy-guild-commands.ts b/scripts/deploy-guild-commands.ts index 56c8a2be..6dc0ed5e 100644 --- a/scripts/deploy-guild-commands.ts +++ b/scripts/deploy-guild-commands.ts @@ -17,7 +17,7 @@ const deploy = async () => { logger.info('[deploy-guild-commands]: Deploying guild commands'); const op = await Result.safe( - deployGuildCommands(commandList, contextMenuCommandList, { + deployGuildCommands([...commandList, ...contextMenuCommandList,], { token, clientId, guildId, diff --git a/src/commands/deploy-command.ts b/src/commands/deploy-command.ts index eab141f5..11015195 100644 --- a/src/commands/deploy-command.ts +++ b/src/commands/deploy-command.ts @@ -19,23 +19,19 @@ const registerCommands = async ({ request, token, body }: DiscordRequestPayload) return rest.put(request, { body }); }; -export const deployGuildCommands = async (commandList: Command[], contextMenuCommandList: ContextMenuCommand[], config: DiscordRequestConfig) => { +export const deployGuildCommands = async (commandList: Array, config: DiscordRequestConfig) => { const { token, clientId, guildId } = config; - const commands = [...commandList, ...contextMenuCommandList].map((cmd) => cmd.data.toJSON()); + const commands = commandList.map((cmd) => cmd.data.toJSON()); const request = Routes.applicationGuildCommands(clientId, guildId); return registerCommands({ request, token, body: commands }); }; -export const deployGlobalCommands = async ( - commandList: Command[], - contextMenuCommandList: ContextMenuCommand[], - config: Omit -) => { +export const deployGlobalCommands = async (commandList: Array, config: Omit) => { const { token, clientId } = config; - const commands = [...commandList, ...contextMenuCommandList].map((cmd) => cmd.data.toJSON()); + const commands = commandList.map((cmd) => cmd.data.toJSON()); const request = Routes.applicationCommands(clientId); return registerCommands({ request, token, body: commands });