|
1 | 1 | import { |
2 | | - ApplicationCommandOption, |
3 | | - ApplicationCommandAttachmentOption, |
4 | | - ApplicationCommandChannelOption, |
5 | | - ApplicationCommandChoicesOption, |
6 | | - ApplicationCommandNonOptions, |
7 | | - ApplicationCommandNumericOption, |
8 | | - ApplicationCommandStringOption, |
9 | | - ApplicationCommandSubCommand, |
10 | | - ApplicationCommandSubGroup, |
| 2 | + ApplicationCommandOptionType, |
| 3 | + BaseApplicationCommandOptionsData, |
| 4 | + ApplicationCommandOptionChoiceData, |
| 5 | + ChannelType, |
11 | 6 | } from 'discord.js'; |
12 | 7 |
|
| 8 | +type OptionSubcommand = ApplicationCommandOptionType.Subcommand | 'Subcommand'; |
| 9 | +type OptionSubcommandGroup = ApplicationCommandOptionType.SubcommandGroup | 'SubcommandGroup'; |
| 10 | +type OptionString = ApplicationCommandOptionType.String | 'String'; |
| 11 | +type OptionInteger = ApplicationCommandOptionType.Integer | 'Integer'; |
| 12 | +type OptionBoolean = ApplicationCommandOptionType.Boolean | 'Boolean'; |
| 13 | +type OptionUser = ApplicationCommandOptionType.User | 'User'; |
| 14 | +type OptionChannel = ApplicationCommandOptionType.Channel | 'Channel'; |
| 15 | +type OptionRole = ApplicationCommandOptionType.Role | 'Role'; |
| 16 | +type OptionMentionable = ApplicationCommandOptionType.Mentionable | 'Mentionable'; |
| 17 | +type OptionNumber = ApplicationCommandOptionType.Number | 'Number'; |
| 18 | +type OptionAttachment = ApplicationCommandOptionType.Attachment | 'Attachment'; |
| 19 | + |
| 20 | +interface ApplicationCommandSubGroup extends Omit<BaseApplicationCommandOptionsData, 'required'> { |
| 21 | + type: OptionSubcommandGroup; |
| 22 | + options?: ApplicationCommandSubCommand[]; |
| 23 | +} |
| 24 | + |
| 25 | +type CommandOptionChoiceResolvableType = OptionString | CommandOptionNumericResolvableType; |
| 26 | +type CommandOptionSubOptionResolvableType = OptionSubcommand | OptionSubcommandGroup; |
| 27 | +type CommandOptionNumericResolvableType = OptionNumber | OptionInteger; |
| 28 | + |
| 29 | +type CommandOptionNonChoiceResolvableType = Exclude< |
| 30 | + ApplicationCommandOptionType, |
| 31 | + CommandOptionChoiceResolvableType | CommandOptionSubOptionResolvableType | OptionChannel |
| 32 | +>; |
| 33 | + |
| 34 | +interface ApplicationCommandNonOptions extends BaseApplicationCommandOptionsData { |
| 35 | + type: Exclude<CommandOptionNonChoiceResolvableType, ApplicationCommandOptionType>; |
| 36 | +} |
| 37 | + |
| 38 | +interface ApplicationCommandChannelOption extends BaseApplicationCommandOptionsData { |
| 39 | + type: OptionChannel; |
| 40 | + channelTypes?: ChannelType[]; |
| 41 | +} |
| 42 | + |
| 43 | +interface ApplicationCommandChoicesOption |
| 44 | + extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> { |
| 45 | + type: CommandOptionChoiceResolvableType; |
| 46 | + choices?: ApplicationCommandOptionChoiceData[]; |
| 47 | + autocomplete?: false; |
| 48 | +} |
| 49 | + |
| 50 | +interface ApplicationCommandChoicesOption |
| 51 | + extends Omit<BaseApplicationCommandOptionsData, 'autocomplete'> { |
| 52 | + type: CommandOptionChoiceResolvableType; |
| 53 | + choices?: ApplicationCommandOptionChoiceData[]; |
| 54 | + autocomplete?: false; |
| 55 | +} |
| 56 | + |
| 57 | +interface ApplicationCommandStringOption extends ApplicationCommandChoicesOption { |
| 58 | + type: OptionString; |
| 59 | + minLength?: number; |
| 60 | + maxLength?: number; |
| 61 | +} |
| 62 | + |
| 63 | +interface ApplicationCommandAttachmentOption extends BaseApplicationCommandOptionsData { |
| 64 | + type: OptionAttachment; |
| 65 | +} |
| 66 | + |
| 67 | +interface ApplicationCommandSubCommand extends Omit<BaseApplicationCommandOptionsData, 'required'> { |
| 68 | + type: OptionSubcommand; |
| 69 | + options?: ( |
| 70 | + | ApplicationCommandChoicesOption |
| 71 | + | ApplicationCommandNonOptions |
| 72 | + | ApplicationCommandChannelOption |
| 73 | + )[]; |
| 74 | +} |
| 75 | + |
| 76 | +interface ApplicationCommandNumericOption extends ApplicationCommandChoicesOption { |
| 77 | + type: CommandOptionNumericResolvableType; |
| 78 | + minValue?: number; |
| 79 | + maxValue?: number; |
| 80 | +} |
| 81 | + |
| 82 | +interface ApplicationCommandRoleOption extends BaseApplicationCommandOptionsData { |
| 83 | + type: OptionRole; |
| 84 | +} |
| 85 | + |
| 86 | +interface ApplicationCommandUserOption extends BaseApplicationCommandOptionsData { |
| 87 | + type: OptionUser; |
| 88 | +} |
| 89 | + |
| 90 | +interface ApplicationCommandMentionableOption extends BaseApplicationCommandOptionsData { |
| 91 | + type: OptionMentionable; |
| 92 | +} |
| 93 | + |
| 94 | +interface ApplicationCommandBooleanOption extends BaseApplicationCommandOptionsData { |
| 95 | + type: OptionBoolean; |
| 96 | +} |
| 97 | + |
13 | 98 | // Patch discord.js' ApplicationCommandOption to reallow the string instead of the enum |
14 | 99 | export type JellyApplicationCommandOption = |
15 | | - | PatchOption<ApplicationCommandSubGroup> |
16 | | - | PatchOption<ApplicationCommandNonOptions> |
17 | | - | PatchOption<ApplicationCommandChannelOption> |
18 | | - | PatchOption<ApplicationCommandChoicesOption> |
19 | | - | PatchOption<ApplicationCommandNumericOption> |
20 | | - | PatchOption<ApplicationCommandStringOption> |
21 | | - | PatchOption<ApplicationCommandAttachmentOption> |
22 | | - | PatchOption<ApplicationCommandSubCommand>; |
23 | | - |
24 | | -interface ReverseApplicationCommandOptionType { |
25 | | - 1: 'Subcommand'; |
26 | | - 2: 'SubcommandGroup'; |
27 | | - 3: 'String'; |
28 | | - 4: 'Integer'; |
29 | | - 5: 'Boolean'; |
30 | | - 6: 'User'; |
31 | | - 7: 'Channel'; |
32 | | - 8: 'Role'; |
33 | | - 9: 'Mentionable'; |
34 | | - 10: 'Number'; |
35 | | - 11: 'Attachment'; |
36 | | -} |
37 | | - |
38 | | -type PatchOption<T extends ApplicationCommandOption> = Omit<T, 'type'> & { |
39 | | - type: T['type'] | ReverseApplicationCommandOptionType[T['type']]; |
40 | | -}; |
| 100 | + | ApplicationCommandSubGroup |
| 101 | + | ApplicationCommandNonOptions |
| 102 | + | ApplicationCommandChannelOption |
| 103 | + | ApplicationCommandChoicesOption |
| 104 | + | ApplicationCommandNumericOption |
| 105 | + | ApplicationCommandStringOption |
| 106 | + | ApplicationCommandRoleOption |
| 107 | + | ApplicationCommandUserOption |
| 108 | + | ApplicationCommandMentionableOption |
| 109 | + | ApplicationCommandBooleanOption |
| 110 | + | ApplicationCommandAttachmentOption |
| 111 | + | ApplicationCommandSubCommand; |
0 commit comments