refactor: Bring CommandType and PluginType to top level

This commit is contained in:
Jacob Nguyen
2022-05-17 17:10:01 -05:00
parent f8987499f6
commit 82f1bad8ff
8 changed files with 32 additions and 32 deletions

View File

@@ -13,9 +13,10 @@
import type { Awaitable, Client } from 'discord.js';
import type { Err, Ok, Result } from 'ts-results';
import type { Module, Override, Wrapper } from '../..';
import type { CommandType } from '../sern';
import type { Module, Override } from '../..';
import type { BaseModule, ModuleDefs } from '../structures/module';
import type { CommandType } from '../structures/enums';
import { PluginType } from '../structures/enums';
export interface Controller {
@@ -23,11 +24,6 @@ export interface Controller {
stop: () => Err<void>;
}
export enum PluginType {
Command = 0b01,
Event = 0b10,
}
type executeCmdPlugin = (controller: Controller) => Result<void, void> ;
type BasePlugin = Override<BaseModule, {
@@ -56,13 +52,11 @@ export function plugins<T extends CommandType>(...plug: (CommandPlugin | EventPl
export function sernModule<T extends CommandType>(
plugs: (CommandPlugin | EventPlugin<T>)[], 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];
};
}