feat: simpler command types

This commit is contained in:
TrèsAbhi committed 2024-03-06 15:38:53 -06:00
1 parent adad668157
commit 49d0dbe86d
1 file changed
+13 -20
+13 -20
View File
@@ -53,38 +53,30 @@ export type InteractionReturnable =
| InteractionIterableReturnable | InteractionIterableReturnable
| Promise<InteractionIterableReturnable>; | Promise<InteractionIterableReturnable>;
type CommandRegistryBase = { interface CommandRegistryBase {
command:
| SlashCommandBuilder
| SlashCommandSubcommandsOnlyBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
};
type CommandRegistryDefinitionBase = {
inProduction: boolean; inProduction: boolean;
inPublic: boolean; inPublic: boolean;
inPreview?: boolean; inPreview?: boolean;
command:
| SlashCommandBuilder
| SlashCommandSubcommandsOnlyBuilder
| Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'>;
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void; autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable; button?: (interaction: ButtonInteraction<CacheType>) => InteractionReturnable;
}; }
type CommandRegistryDefinitionHandlesInteraction = { interface CommandRegistryImplicit extends CommandRegistryBase {
handlesInteraction: true; handlesInteraction: true;
handler: (interaction: ChatInputCommandInteraction<CacheType>) => void; handler: (interaction: ChatInputCommandInteraction<CacheType>) => void;
}; }
type CommandRegistryDefinitionDoesHandleInteraction = { interface CommandRegistryExplicit extends CommandRegistryBase {
handlesInteraction?: false; handlesInteraction?: false;
handler: ( handler: (
interaction: ChatInputCommandInteraction<CacheType>, interaction: ChatInputCommandInteraction<CacheType>,
) => InteractionReturnable; ) => InteractionReturnable;
}; }
export type CommandRegistry = CommandRegistryBase & export type CommandRegistry = CommandRegistryImplicit | CommandRegistryExplicit;
(CommandRegistryDefinitionBase &
(
| CommandRegistryDefinitionHandlesInteraction
| CommandRegistryDefinitionDoesHandleInteraction
));
const rest = new REST().setToken(secrets.DISCORD_TOKEN);
export const COMMANDS_RAW: Promise<CommandRegistry>[] = [ export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
permissionsCommand, 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 guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[]; [];
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =