mirror of
https://github.com/sern-handler/handler
synced 2026-06-25 01:02:17 +00:00
feat (handler) moving to dev build; new module types
This commit is contained in:
@@ -8,19 +8,16 @@ interface BaseModule {
|
||||
name? : string;
|
||||
description : string;
|
||||
execute() : Awaitable<possibleOutput | void>
|
||||
plugins? : [] //TODO
|
||||
}
|
||||
|
||||
type TextCommand = { moduleType : CommandType.TEXT; alias : string[] | [] };
|
||||
type SlashCommand = { moduleType : CommandType.SLASH; options : ApplicationCommandOptionData[] | [] };
|
||||
type BothCommand = { moduleType : CommandType.BOTH; alias : string[] | []; options : ApplicationCommandOptionData[] | [] }
|
||||
export type Text= { type : CommandType.TEXT; alias : string[] | [] };
|
||||
export type Slash={ type : CommandType.SLASH; options : ApplicationCommandOptionData[] | [] };
|
||||
export type Both= { type : CommandType.BOTH; alias : string[] | []; options : ApplicationCommandOptionData[] | [] }
|
||||
|
||||
export type Module =
|
||||
BaseModule & (
|
||||
TextCommand
|
||||
| SlashCommand
|
||||
| BothCommand
|
||||
);
|
||||
BaseModule
|
||||
& Slash | Both | Text;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
30
src/handler/structures/commands/moduleHandler.ts
Normal file
30
src/handler/structures/commands/moduleHandler.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { CommandType } from "../../sern";
|
||||
import { SernError } from "../errors";
|
||||
import type { Modules } from "../structxports";
|
||||
|
||||
export type TextAction = ( mod : Modules.Text ) => unknown;
|
||||
export type BothAction = ( mod : Modules.Both) => unknown;
|
||||
export type SlashAction= ( mod : Modules.Slash) => unknown;
|
||||
|
||||
export type Action =
|
||||
TextAction
|
||||
| BothAction
|
||||
| SlashAction;
|
||||
|
||||
|
||||
export function onModule<T extends Modules.Module> ( mod: T, action : Action ) : unknown {
|
||||
switch (mod.type) {
|
||||
case CommandType.TEXT : {
|
||||
return (action as TextAction)(mod);
|
||||
}
|
||||
case CommandType.SLASH : {
|
||||
return (action as SlashAction)(mod);
|
||||
}
|
||||
case CommandType.BOTH : {
|
||||
return (action as BothAction)(mod);
|
||||
}
|
||||
default : throw Error(SernError.NOT_VALID_MOD_TYPE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export enum SernError {
|
||||
RESERVED_EVENT = 'Cannot register the reserved ready event. Please use the init property.',
|
||||
NO_ALIAS = 'You cannot provide an array with elements to a slash command.'
|
||||
NO_ALIAS = 'You cannot provide an array with elements to a slash command.',
|
||||
NOT_VALID_MOD_TYPE = 'Detected an unknown module type'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Context from './context';
|
||||
import type Module from './module';
|
||||
import * as ModuleTypes from './commands/module';
|
||||
import type Wrapper from './wrapper';
|
||||
|
||||
export { Context, Module, Wrapper };
|
||||
export { Context, ModuleTypes, Wrapper };
|
||||
|
||||
Reference in New Issue
Block a user