mirror of
https://github.com/SrIzan10/handler.git
synced 2026-05-01 10:45:17 +00:00
refactor: Bring CommandType and PluginType to top level
This commit is contained in:
@@ -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];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user