diff --git a/src/handler/structures/enums.ts b/src/handler/structures/enums.ts index 9aefe37..82d3927 100644 --- a/src/handler/structures/enums.ts +++ b/src/handler/structures/enums.ts @@ -2,14 +2,17 @@ * @enum { number }; */ enum CommandType { - Text = 0b00000001, - Slash = 0b00000010, - MenuUser = 0b00000100, - MenuMsg = 0b00001000, - Button = 0b00010000, - MenuSelect = 0b00100000, - Modal = 0b01000000, - Autocomplete = 0b10000000, + Text = 0b00000000001, + Slash = 0b00000000010, + MenuUser = 0b00000000100, + MenuMsg = 0b0000001000, + Button = 0b00000010000, + MenuSelect = 0b00000100000, + Modal = 0b00001000000, + Autocomplete = 0b00010000000, + Discord = 0b00100000000, + External = 0b01000000000, + Sern = 0b10000000000, Both = 0b0000011, } diff --git a/src/handler/structures/events.ts b/src/handler/structures/events.ts new file mode 100644 index 0000000..f97332a --- /dev/null +++ b/src/handler/structures/events.ts @@ -0,0 +1,38 @@ +import type { Override } from '../../types/handler'; +import type { BaseModule } from './module'; +import type { CommandPlugin, EventPlugin } from '../plugins/plugin'; +import type { CommandType } from './enums'; +import type { SernEventsMapping } from '../sernEmitter'; +import type { Awaitable, ClientEvents } from 'discord.js'; + +export type SernEventCommand = + Override< + BaseModule, + { + name?: T; + type: CommandType.Sern; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; + execute(...args: SernEventsMapping[T]): Awaitable; + } + >; +export type DiscordEventCommand = Override< + BaseModule, + { + name?: T; + type: CommandType.Discord; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; + execute(...args: ClientEvents[T]): Awaitable; + } +>; + +export type ExternalEventCommand = Override< + BaseModule, + { + type: CommandType.External; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; + execute(...args: unknown[]): Awaitable; + } +>; diff --git a/src/handler/utilities/predicates.ts b/src/handler/utilities/predicates.ts index c6b5347..a51a10f 100644 --- a/src/handler/utilities/predicates.ts +++ b/src/handler/utilities/predicates.ts @@ -1,4 +1,4 @@ -import type { Module, ModuleDefs } from '../structures/module'; +import type { EventModule, Module, ModuleDefs } from '../structures/module'; import type { Awaitable, ButtonInteraction, @@ -10,6 +10,7 @@ import type { UserContextMenuCommandInteraction, } from 'discord.js'; import type { DiscordEvent, EventEmitterRegister, SernEvent } from '../..'; +import { CommandType } from '../..'; export function correctModuleType( plug: Module | undefined, @@ -57,3 +58,7 @@ export function isDiscordEvent( export function isSernEvent(el: DiscordEvent | EventEmitterRegister | SernEvent): el is SernEvent { return !isDiscordEvent(el); } + +export function isEventModule(module: Module): module is EventModule { + return [CommandType.Discord, CommandType.Sern, CommandType.External].includes(module.type); +}