From c40b75d333700f2158eb9f22c08bac90fbf6a4e8 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 17 May 2022 16:05:35 -0500 Subject: [PATCH] refactor: Simplify sernModule handler signature --- src/handler/plugins/plugin.ts | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index 52ed9a9..3abaec4 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -28,40 +28,41 @@ export enum PluginType { Event = 0b10, } -type executeCmdPlugin = { execute: (wrapper: Wrapper, controller: Controller) => Result }; +type executeCmdPlugin = (controller: Controller) => Result ; -interface BasePlugin extends Override { - type: PluginType; -} +type BasePlugin = Override; -export type CommandPlugin = { +export type CommandPlugin = Override Awaitable>; - }>; + execute: (wrapper: Client, module: Module, controller: Controller) => Awaitable>; +}>; //TODO: rn adding the modType check a little hackish. Find better way to determine the // module type of the event plugin -export type EventPlugin = { +export type EventPlugin = Override, controller: Controller) => Awaitable>; - }>; + execute: (event: Parameters, controller: Controller) => Awaitable>; +}>; -export function plugins(...plug: CommandPlugin[]): CommandPlugin[]; -export function plugins(...plug: EventPlugin[]): EventPlugin[]; -export function plugins(...plug: CommandPlugin[] | EventPlugin[]) { +export function plugins(...plug: (CommandPlugin | EventPlugin)[]) { return plug; } -export function sernModule(plugins : CommandPlugin[], onEvent: EventPlugin[], mod: Omit) { - // return { - // plugins, - // onEvent, - // ...mod, - // }; +export function sernModule( + plugs: (CommandPlugin | EventPlugin)[], mod : ModuleDefs[T] +) : ModuleDefs[T] { + //mod.plugins if defined, warn user to use first parameter + //mod.onEvent if defined, warn user to use first parameter + const plugins = plugs.filter(el => el.type === PluginType.Command); + const onEvent = plugs.filter(el => el.type === PluginType.Event); + return { + plugins, + onEvent, + ...mod + } as unknown as ModuleDefs[T]; }