diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index f2165f1..2c7d707 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -1,7 +1,14 @@ import type { ApplicationCommandAutocompleteOption, + ApplicationCommandChannelOptionData, + ApplicationCommandChoicesData, + ApplicationCommandNonOptionsData, + ApplicationCommandNumericOptionData, ApplicationCommandOptionData, + ApplicationCommandSubCommandData, + ApplicationCommandSubGroupData, Awaitable, + BaseApplicationCommandOptionsData, ButtonInteraction, MessageContextMenuCommandInteraction, ModalSubmitInteraction, @@ -39,7 +46,7 @@ export type SlashCommand = Override< type: CommandType.Slash; onEvent?: EventPlugin[]; plugins?: CommandPlugin[]; - options?: OptionsData[]; + options?: SernOptionsData[]; } >; @@ -50,7 +57,7 @@ export type BothCommand = Override< onEvent?: EventPlugin[]; plugins?: CommandPlugin[]; alias?: string[]; - options?: OptionsData[]; + options?: SernOptionsData[]; } >; @@ -143,16 +150,52 @@ export type ModuleDefs = { [CommandType.Autocomplete]: AutocompleteCommand; }; -export type OptionsData = - | Exclude - | { - name: string; - description: string; - autocomplete: true; - required?: boolean; - type: - | ApplicationCommandOptionType.String - | ApplicationCommandOptionType.Number - | ApplicationCommandOptionType.Integer; - command: Omit; - }; +//TODO: support deeply nested Autocomplete +// objective: construct union of ApplicationCommandOptionData change any Autocomplete data +// into Sern autocomplete data. + +export type SernAutocompleteData = Override< + BaseApplicationCommandOptionsData, + { + autocomplete: true; + type: + | ApplicationCommandOptionType.String + | ApplicationCommandOptionType.Number + | ApplicationCommandOptionType.Integer; + command: Omit; + } +>; + +/** + * Type that just uses SernAutocompleteData and not regular autocomplete + */ +export type BaseOptions = + | ApplicationCommandChoicesData + | ApplicationCommandNonOptionsData + | ApplicationCommandChannelOptionData + | ApplicationCommandAutocompleteOption + | ApplicationCommandNumericOptionData + | SernAutocompleteData; + +export type SernSubCommandData = Override< + Omit, + { + type: ApplicationCommandOptionType.Subcommand; + options?: BaseOptions[]; + } +>; + +export type SernSubCommandGroupData = Override< + Omit, + { + type: ApplicationCommandOptionType.SubcommandGroup; + options?: SernSubCommandData[]; + } +>; + +export type SernOptionsData = + U extends ApplicationCommandSubCommandData + ? SernSubCommandData + : U extends ApplicationCommandSubGroupData + ? SernSubCommandGroupData + : BaseOptions; diff --git a/src/handler/utilities/optionsBuilder.ts b/src/handler/utilities/optionsBuilder.ts new file mode 100644 index 0000000..a99453a --- /dev/null +++ b/src/handler/utilities/optionsBuilder.ts @@ -0,0 +1,8 @@ +import type { SernOptionsData } from '../structures/module'; +import type { ApplicationCommandOptionData } from 'discord.js'; + +class OptionsBuilder { + public constructor(private options: ApplicationCommandOptionData[] = []) { + this.options = options; + } +}