mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
feat: Changing types of wrapper for external and sern emitter
This commit is contained in:
@@ -18,6 +18,8 @@ import { CommandType } from '../..';
|
||||
import type { AutocompleteCommand, BaseModule, ModuleDefs } from '../structures/module';
|
||||
import { PluginType } from '../structures/enums';
|
||||
import type { EventEmitter } from 'events';
|
||||
import type { ExternalEventCommand, SernEventCommand } from '../structures/events';
|
||||
import type SernEmitter from '../sernEmitter';
|
||||
|
||||
export interface Controller {
|
||||
next: () => Ok<void>;
|
||||
@@ -37,13 +39,38 @@ export type CommandPlugin<T extends keyof ModuleDefs = keyof ModuleDefs> = {
|
||||
{
|
||||
type: PluginType.Command;
|
||||
execute: (
|
||||
wrapper: K extends CommandType.External ? EventEmitter : Client,
|
||||
wrapper: Client,
|
||||
module: DefinitelyDefined<ModuleDefs[T], 'name' | 'description'>,
|
||||
controller: Controller,
|
||||
) => Awaitable<Result<void, void>>;
|
||||
}
|
||||
>;
|
||||
}[T];
|
||||
|
||||
export type ExternalEmitterPlugin<T extends EventEmitter = EventEmitter> = Override<
|
||||
BasePlugin,
|
||||
{
|
||||
type: PluginType.Command;
|
||||
execute: (
|
||||
wrapper: T,
|
||||
module: DefinitelyDefined<ExternalEventCommand, 'name' | 'description'>,
|
||||
controller: Controller,
|
||||
) => Awaitable<Result<void, void>>;
|
||||
}
|
||||
>;
|
||||
|
||||
export type SernEmitterPlugin = Override<
|
||||
BasePlugin,
|
||||
{
|
||||
type: PluginType.Command;
|
||||
execute: (
|
||||
wrapper: SernEmitter,
|
||||
module: DefinitelyDefined<SernEventCommand, 'name' | 'description'>,
|
||||
controller: Controller,
|
||||
) => Awaitable<Result<void, void>>;
|
||||
}
|
||||
>;
|
||||
|
||||
export type EventPlugin<T extends keyof ModuleDefs = keyof ModuleDefs> = {
|
||||
[K in T]: Override<
|
||||
BasePlugin,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import type { Override } from '../../types/handler';
|
||||
import type { BaseModule } from './module';
|
||||
import type { CommandPlugin, EventPlugin } from '../plugins/plugin';
|
||||
import type {
|
||||
CommandPlugin,
|
||||
EventPlugin,
|
||||
ExternalEmitterPlugin,
|
||||
SernEmitterPlugin,
|
||||
} from '../plugins/plugin';
|
||||
import type { CommandType } from './enums';
|
||||
import type { SernEventsMapping } from '../sernEmitter';
|
||||
import type { Awaitable, ClientEvents } from 'discord.js';
|
||||
@@ -13,7 +18,7 @@ export type SernEventCommand<T extends keyof SernEventsMapping = keyof SernEvent
|
||||
name?: T;
|
||||
type: CommandType.Sern;
|
||||
onEvent: EventPlugin<CommandType.Sern>[];
|
||||
plugins: CommandPlugin[];
|
||||
plugins: SernEmitterPlugin[];
|
||||
execute(...args: SernEventsMapping[T]): Awaitable<void | unknown>;
|
||||
}
|
||||
>;
|
||||
@@ -31,10 +36,10 @@ export type DiscordEventCommand<T extends keyof ClientEvents = keyof ClientEvent
|
||||
export type ExternalEventCommand = Override<
|
||||
BaseModule,
|
||||
{
|
||||
emitter: string;
|
||||
type: CommandType.External;
|
||||
emitter: EventEmitter;
|
||||
onEvent: EventPlugin<CommandType.External>[];
|
||||
plugins: CommandPlugin[];
|
||||
plugins: ExternalEmitterPlugin[];
|
||||
execute(...args: unknown[]): Awaitable<void | unknown>;
|
||||
}
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user