feat (handler) moving to dev build; new module types

This commit is contained in:
Jacob Nguyen
2022-03-15 15:12:58 -05:00
parent 5a1870be73
commit 3178f18d56
6 changed files with 205 additions and 109 deletions

View File

@@ -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;

View 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);
}
}

View File

@@ -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'
}

View File

@@ -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 };