diff --git a/src/core/modules.ts b/src/core/modules.ts index d944f84c..c20f364b 100644 --- a/src/core/modules.ts +++ b/src/core/modules.ts @@ -1,5 +1,15 @@ -import { ClientEvents } from 'discord.js'; -import { CommandType, EventType, PluginType } from '../core/structures'; +import { + ButtonInteraction, + ChannelSelectMenuInteraction, + ClientEvents, + MentionableSelectMenuInteraction, + MessageContextMenuCommandInteraction, + ModalSubmitInteraction, + RoleSelectMenuInteraction, + StringSelectMenuInteraction, + UserSelectMenuInteraction, +} from 'discord.js'; +import { CommandType, Context, EventType, PluginType } from '../core/structures'; import type { AnyCommandPlugin, AnyEventPlugin, @@ -14,9 +24,10 @@ import type { InputCommand, InputEvent, Module, + SernOptionsData, } from '../types/core-modules'; import { partitionPlugins } from './_internal'; -import type { Awaitable } from '../types/utility'; +import type { Args, Awaitable, SlashOptions } from '../types/utility'; /** * @since 1.0.0 The wrapper function to define command modules for sern @@ -30,6 +41,174 @@ export function commandModule(mod: InputCommand): CommandModule { plugins, } as CommandModule; } +/** + * @since 3.2.0 The wrapper function to create Both Commands for sern. + * @param mod + */ +export function bothCommand(mod: { + name?: string; + description: string; + options?: SernOptionsData[]; + plugins?: (InitPlugin | ControlPlugin)[]; + execute: (ctx: Context, options: Args) => Awaitable; +}): CommandModule { + return commandModule({ + type: CommandType.Both, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Slash Commands for sern. + * @param mod + */ +export function slashCommand(mod: { + name?: string; + description: string; + options?: SernOptionsData[]; + plugins?: (InitPlugin | ControlPlugin)[]; + execute: (ctx: Context, options: ['slash', SlashOptions]) => Awaitable; +}) { + return commandModule({ + type: CommandType.Slash, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Text Commands for sern. + * @param mod + */ +export function textCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: Context, options: ['text', string[]]) => Awaitable; +}) { + return commandModule({ + type: CommandType.Text, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Modal Commands for sern. + * @param mod + */ +export function modalCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: ModalSubmitInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.Modal, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Button Commands for sern. + * @param mod + */ +export function buttonCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: ButtonInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.Button, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create String Select Menu Commands for sern. + * @param mod + */ +export function stringSelectMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: StringSelectMenuInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.StringSelect, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Mention Select Menu Commands for sern. + * @param mod + */ +export function mentionableSelectMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: MentionableSelectMenuInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.MentionableSelect, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Channel Select Menu Commands for sern. + * @param mod + */ +export function channelSelectMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: ChannelSelectMenuInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.ChannelSelect, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create User Select Menu Commands for sern. + * @param mod + */ +export function userSelectMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: UserSelectMenuInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.UserSelect, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Role Select Menu Commands for sern. + * @param mod + */ +export function roleSelectMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: RoleSelectMenuInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.RoleSelect, + ...mod, + }); +} +/** + * @since 3.2.0 The wrapper function to create Msg Context2 Menu Commands for sern. + * @param mod + */ +export function msgContextMenuCommand(mod: { + name?: string; + description: string; + plugins?: AnyCommandPlugin[]; + execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable; +}) { + return commandModule({ + type: CommandType.CtxMsg, + ...mod, + }); +} + /** * @since 1.0.0 * The wrapper function to define event modules for sern @@ -76,7 +255,7 @@ function prepareClassPlugins(c: Module) { */ export abstract class CommandExecutable { abstract type: Type; - plugins: AnyCommandPlugin[] = []; + plugins?: AnyCommandPlugin[] = []; private static _instance: CommandModule; static getInstance() { @@ -97,7 +276,7 @@ export abstract class CommandExecutable { abstract type: Type; - plugins: AnyEventPlugin[] = []; + plugins?: AnyEventPlugin[] = []; private static _instance: EventModule; static getInstance() { diff --git a/src/index.ts b/src/index.ts index 62bcbad8..80acfee4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -44,13 +44,22 @@ export type { Singleton, Transient, CoreDependencies, Initializable } from './ty export { commandModule, + bothCommand, + textCommand, + modalCommand, + slashCommand, + buttonCommand, + msgContextMenuCommand, + roleSelectMenuCommand, + userSelectMenuCommand, + stringSelectMenuCommand, + channelSelectMenuCommand, + mentionableSelectMenuCommand, eventModule, discordEvent, EventExecutable, CommandExecutable, } from './core/modules'; -export { - useContainerRaw -} from './core/_internal' +export { useContainerRaw } from './core/_internal'; export { controller } from './sern';