From 49d0dbe86d332c2e8ac7a002e30b1cec4220a958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:38:53 -0600 Subject: [PATCH] feat: simpler command types --- src/events/interactionCreate/index.ts | 33 +++++++++++---------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index c90b78c6c..3008bf026 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -53,38 +53,30 @@ export type InteractionReturnable = | InteractionIterableReturnable | Promise; -type CommandRegistryBase = { - command: - | SlashCommandBuilder - | SlashCommandSubcommandsOnlyBuilder - | Omit; -}; -type CommandRegistryDefinitionBase = { +interface CommandRegistryBase { inProduction: boolean; inPublic: boolean; inPreview?: boolean; + command: + | SlashCommandBuilder + | SlashCommandSubcommandsOnlyBuilder + | Omit; + autocomplete?: (interaction: AutocompleteInteraction) => void; button?: (interaction: ButtonInteraction) => InteractionReturnable; -}; -type CommandRegistryDefinitionHandlesInteraction = { +} +interface CommandRegistryImplicit extends CommandRegistryBase { handlesInteraction: true; handler: (interaction: ChatInputCommandInteraction) => void; -}; -type CommandRegistryDefinitionDoesHandleInteraction = { +} +interface CommandRegistryExplicit extends CommandRegistryBase { handlesInteraction?: false; handler: ( interaction: ChatInputCommandInteraction, ) => InteractionReturnable; -}; -export type CommandRegistry = CommandRegistryBase & - (CommandRegistryDefinitionBase & - ( - | CommandRegistryDefinitionHandlesInteraction - | CommandRegistryDefinitionDoesHandleInteraction - )); - -const rest = new REST().setToken(secrets.DISCORD_TOKEN); +} +export type CommandRegistry = CommandRegistryImplicit | CommandRegistryExplicit; export const COMMANDS_RAW: Promise[] = [ permissionsCommand, @@ -118,6 +110,7 @@ export const commands = Promise.allSettled(COMMANDS_RAW).then((rawCommands) => { ); }); +const rest = new REST().setToken(secrets.DISCORD_TOKEN); export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =