From cf85a5db6413e2b8b42143f70964f7a19789e1ff Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Tue, 17 May 2022 18:57:01 -0500 Subject: [PATCH] fix: Fix return type of sernModule --- src/handler/plugins/plugin.ts | 27 ++++++++++++--------------- src/handler/structures/module.ts | 6 +++--- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index 19f6d22..15d75e9 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -15,8 +15,8 @@ import type { Awaitable, Client } from 'discord.js'; import type { Err, Ok, Result } from 'ts-results'; import type { Module, Override } from '../..'; import type { BaseModule, ModuleDefs } from '../structures/module'; -import type { CommandType } from '../structures/enums'; -import { PluginType } from '../structures/enums'; +import type { PluginType } from '../structures/enums'; +import type { ValueOf } from 'ts-pattern/dist/types/helpers'; export interface Controller { @@ -24,11 +24,8 @@ export interface Controller { stop: () => Err; } -type executeCmdPlugin = (controller: Controller) => Result ; - type BasePlugin = Override; export type CommandPlugin = Override = Override = Override, controller: Controller) => Awaitable>; }>; - -export function plugins(...plug: (CommandPlugin | EventPlugin)[]) { +export function plugins(...plug: CommandPlugin[]) { return plug; } -export function sernModule( - plugs: (CommandPlugin | EventPlugin)[], mod : ModuleDefs[T] -) : ModuleDefs[T] { - const plugins = plugs.filter(el => el.type === PluginType.Command); - const onEvent = plugs.filter(el => el.type === PluginType.Event); +type ModuleNoPlugins = ValueOf<{ + [T in keyof ModuleDefs] : Omit +}> + +export function sernModule( + plugins: (CommandPlugin)[], mod : ModuleNoPlugins +) : Module { return { plugins, - onEvent, ...mod }; } diff --git a/src/handler/structures/module.ts b/src/handler/structures/module.ts index cd208ee..ec1194a 100644 --- a/src/handler/structures/module.ts +++ b/src/handler/structures/module.ts @@ -30,14 +30,14 @@ export type TextCommand = Override[] - plugins?: (CommandPlugin)[]; + plugins?: CommandPlugin[]; options?: ApplicationCommandOptionData[]; }>; export type BothCommand = Override[] - plugins?: (CommandPlugin)[] + plugins?: CommandPlugin[] alias?: string[]; options?: ApplicationCommandOptionData[]; }>; @@ -45,7 +45,7 @@ export type BothCommand = Override[]; - plugins?: (CommandPlugin)[]; + plugins?: CommandPlugin[]; execute: (ctx: UserContextMenuCommandInteraction) => Awaitable }>