diff --git a/src/handler/utilities/higherOrders.ts b/src/handler/utilities/higherOrders.ts index 9b4e872..1174e4f 100644 --- a/src/handler/utilities/higherOrders.ts +++ b/src/handler/utilities/higherOrders.ts @@ -1,4 +1,5 @@ -import type { Message } from 'discord.js'; +import type { Application, ApplicationCommandOptionData, Message } from 'discord.js'; +import type { OptionData } from './options'; type MsgFnArgs = [msgOrInter: Message, prefix?: string]; type MsgFn = (...args: MsgFnArgs) => boolean; @@ -8,10 +9,18 @@ type MsgFn = (...args: MsgFnArgs) => boolean; * @param {MsgFn} fn any function that has argument `MsgFnArgs` returning boolean * @returns {(message: Message, prefix: string) => boolean} */ -export function AllTrue(...fns : MsgFn[]) : - (message: Message, prefix: string) => boolean { +export function AllTrue(...fns: MsgFn[]): + (message: Message, prefix: string) => boolean { return (message: Message, prefix: string) => { return fns.every(g => g(message, prefix)); }; } +/** + * A HoF that acts as a ligtweight slash command options builder, enabling user with intellisense + * @param { T extends keyof OptionData } type type of option + * @returns { (optionData: Omit) => ApplicationCommandOptionData | Omit } creates options + */ +export function Option(type: T) { + return (optionData: Omit) => { return { type, ...optionData }; }; +} \ No newline at end of file diff --git a/src/handler/utilities/options.ts b/src/handler/utilities/options.ts new file mode 100644 index 0000000..b91ed39 --- /dev/null +++ b/src/handler/utilities/options.ts @@ -0,0 +1,26 @@ +import type { + ApplicationCommandAutocompleteOption, + ApplicationCommandChannelOptionData, + ApplicationCommandChoicesOption, + ApplicationCommandNonOptionsData, + ApplicationCommandNumericOptionData, + ApplicationCommandSubCommandData, + ApplicationCommandSubGroupData +} from 'discord.js'; + +type BaseOption = { name : string, description : string, required : false }; + +export interface OptionData { + SUB_COMMAND: ApplicationCommandSubCommandData + SUB_COMMAND_GROUP: ApplicationCommandSubGroupData + NONE: ApplicationCommandNonOptionsData + CHANNEL: ApplicationCommandChannelOptionData + CHOICE: ApplicationCommandChoicesOption + AUTO: ApplicationCommandAutocompleteOption + NUMBER: ApplicationCommandNumericOptionData + INTEGER: ApplicationCommandNumericOptionData + USER : { type: "USER" } & BaseOption + MENTIONABLE: { type : "MENTIONABLE" } & BaseOption + ROLE : { type: "ROLE" } & BaseOption + BOOLEAN : { type: "BOOLEAN" } & BaseOption +} \ No newline at end of file