From d0320cea39a334bf997a6ae9f32b2aa32d1de6ba Mon Sep 17 00:00:00 2001 From: NotNite Date: Wed, 22 Jan 2025 20:30:15 -0500 Subject: [PATCH] More command types --- .../src/commands/webpackModules/commands.ts | 2 +- packages/types/src/coreExtensions/commands.ts | 99 ++++++++++++++++--- 2 files changed, 85 insertions(+), 16 deletions(-) diff --git a/packages/core-extensions/src/commands/webpackModules/commands.ts b/packages/core-extensions/src/commands/webpackModules/commands.ts index 62fd090..b7d9d7e 100644 --- a/packages/core-extensions/src/commands/webpackModules/commands.ts +++ b/packages/core-extensions/src/commands/webpackModules/commands.ts @@ -30,7 +30,7 @@ export const commands: Commands = { applicationId: APPLICATION_ID, untranslatedDescription: command.description, displayDescription: command.description, - options: command.options.map((o) => ({ + options: command.options?.map((o) => ({ ...o, displayName: o.name, displayDescription: o.description diff --git a/packages/types/src/coreExtensions/commands.ts b/packages/types/src/coreExtensions/commands.ts index 3d7fedc..270b523 100644 --- a/packages/types/src/coreExtensions/commands.ts +++ b/packages/types/src/coreExtensions/commands.ts @@ -16,33 +16,90 @@ export enum InputType { } export enum OptionType { - ATTACHMENT = 11, + SUB_COMMAND = 1, + SUB_COMMAND_GROUP = 2, + STRING = 3, + INTEGER = 4, BOOLEAN = 5, + USER = 6, CHANNEL = 7, - INTEGER = 4, + ROLE = 8, MENTIONABLE = 9, NUMBER = 10, - ROLE = 8, - STRING = 3, - SUB_COMMAND = 1, - SUB_COMMAND_GROUP = 2, - USER = 6 + ATTACHMENT = 11 } -export type RegisteredCommandOption = { - name: string; +export enum ChannelType { + GUILD_TEXT = 0, + DM = 1, + GUILD_VOICE = 2, + GROUP_DM = 3, + GUILD_CATEGORY = 4, + GUILD_ANNOUNCEMENT = 5, + GUILD_STORE = 6, + ANNOUNCEMENT_THREAD = 10, + PUBLIC_THREAD = 11, + PRIVATE_THREAD = 12, + GUILD_STAGE_VOICE = 13, + GUILD_DIRECTORY = 14, + GUILD_FORUM = 15, + GUILD_MEDIA = 16, + LOBBY = 17, + DM_SDK = 18 +} + +export type RegisteredCommandOption = MoonlightCommandOption & { displayName: string; - type: OptionType; - description: string; displayDescription: string; }; -export type MoonlightCommandOption = { +export type CommandOptionChoice = { + name: string; + value: T; +}; + +type CommandOptionBase = { + type: T; name: string; - type: OptionType; description: string; + required?: T extends OptionType.SUB_COMMAND + ? never + : T extends OptionType.SUB_COMMAND_GROUP + ? never + : boolean | undefined; + choices?: T extends OptionType.STRING + ? CommandOptionChoice[] + : T extends OptionType.INTEGER + ? CommandOptionChoice[] + : T extends OptionType.NUMBER + ? CommandOptionChoice[] + : never; + options?: T extends OptionType.SUB_COMMAND + ? MoonlightCommandOption[] + : T extends OptionType.SUB_COMMAND_GROUP + ? MoonlightCommandOption[] + : never; + channelTypes?: T extends OptionType.CHANNEL ? ChannelType[] : never; + minValue?: T extends OptionType.INTEGER ? number : T extends OptionType.NUMBER ? number : never; + maxValue?: T extends OptionType.INTEGER ? number : T extends OptionType.NUMBER ? number : never; + minLength?: T extends OptionType.STRING ? number : never; + maxLength?: T extends OptionType.STRING ? number : never; }; +// This is bad lol +export type MoonlightCommandOption = + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase + | CommandOptionBase; + // TODO: types export type CommandPredicateState = { channel: any; @@ -58,7 +115,7 @@ export type RegisteredCommand = { applicationId: string; // set to -3! untranslatedDescription: string; displayDescription: string; - options: RegisteredCommandOption[]; + options?: RegisteredCommandOption[]; predicate?: (state: CommandPredicateState) => boolean; execute: (options: CommandOption[]) => void; }; @@ -76,7 +133,7 @@ export type MoonlightCommand = { * You likely want BUILT_IN (or BUILT_IN_TEXT if usable with replies) */ inputType: InputType; - options: MoonlightCommandOption[]; + options?: MoonlightCommandOption[]; predicate?: (state: CommandPredicateState) => boolean; execute: (options: CommandOption[]) => void; }; @@ -92,6 +149,18 @@ export type CommandOption = { type: OptionType.STRING; value: string; } + | { + type: OptionType.NUMBER | OptionType.INTEGER; + value: number; + } + | { + type: OptionType.BOOLEAN; + value: boolean; + } + | { + type: OptionType.SUB_COMMAND | OptionType.SUB_COMMAND_GROUP; + options: CommandOption[]; + } ); export type AnyScopeRegex = RegExp["exec"] & {