mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: add events.ts for more customizable event handling
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
38
src/handler/structures/events.ts
Normal file
38
src/handler/structures/events.ts
Normal file
@@ -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<T extends keyof SernEventsMapping = keyof SernEventsMapping> =
|
||||
Override<
|
||||
BaseModule,
|
||||
{
|
||||
name?: T;
|
||||
type: CommandType.Sern;
|
||||
onEvent: EventPlugin<CommandType.Sern>[];
|
||||
plugins: CommandPlugin[];
|
||||
execute(...args: SernEventsMapping[T]): Awaitable<void | unknown>;
|
||||
}
|
||||
>;
|
||||
export type DiscordEventCommand<T extends keyof ClientEvents = keyof ClientEvents> = Override<
|
||||
BaseModule,
|
||||
{
|
||||
name?: T;
|
||||
type: CommandType.Discord;
|
||||
onEvent: EventPlugin<CommandType.Discord>[];
|
||||
plugins: CommandPlugin[];
|
||||
execute(...args: ClientEvents[T]): Awaitable<void | unknown>;
|
||||
}
|
||||
>;
|
||||
|
||||
export type ExternalEventCommand = Override<
|
||||
BaseModule,
|
||||
{
|
||||
type: CommandType.External;
|
||||
onEvent: EventPlugin<CommandType.External>[];
|
||||
plugins: CommandPlugin[];
|
||||
execute(...args: unknown[]): Awaitable<void | unknown>;
|
||||
}
|
||||
>;
|
||||
@@ -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<T extends keyof ModuleDefs>(
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user