diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 3068e71..db73e64 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -2,13 +2,10 @@ import type { Arg, Context, Nullable, ParseType, Visibility } from "../types/ha import { Files } from "./utils/readFile" import type { ApplicationCommandOptionData, Awaitable, Client, CommandInteraction, CommandInteractionOptionResolver, Message} from "discord.js"; import type { possibleOutput } from "../types/handler/handler" -import { Err, Ok, Result, Option, None, Some } from "ts-results"; +import { Ok, Result, None, Some } from "ts-results"; import type { Utils } from "./utils/preprocessors/args"; import { CtxHandler } from "./utils/ctxHandler"; - - - export namespace Sern { export class Handler { private wrapper: Sern.Wrapper; @@ -20,8 +17,6 @@ export namespace Sern { .on("ready", async () => { if (this.wrapper.init !== undefined) this.wrapper.init(this); await Files.registerModules(this); - - }) .on("messageCreate", async message => { @@ -119,6 +114,22 @@ export namespace Sern { init? : (handler : Sern.Handler) => void, readonly privateServerId : string } + /** + * Module Interfaces. Will be used to configure commands across folders + * Name of command is taken from filename itself. + * Example command in `ping.ts` + *```ts + * export default { + * alias : string[], // any other names the command would be + * desc : string, // description of command + * visibility: "public" | "private", + * //main command that gets executed + * delegate : ( eventParams : Context , args: Ok ) => Awaitable | void>, + * //if command has arguments needing parsing, this exists + * parse?: (ctx: Context, args: ParseType ) => Utils.ArgType + * } as Sern.Module + * ``` + */ export interface Module { alias: string[], desc : string, @@ -127,10 +138,9 @@ export namespace Sern { delegate : ( eventParams : Context , args: Ok ) => Awaitable | void> parse? : (ctx: Context, args: ParseType ) => Utils.ArgType } - export enum CommandType { - TEXT = 2, - SLASH = 4, + TEXT = 1, + SLASH = 2, } } diff --git a/src/handler/utils/readFile.ts b/src/handler/utils/readFile.ts index 2d874f8..9eb06f1 100644 --- a/src/handler/utils/readFile.ts +++ b/src/handler/utils/readFile.ts @@ -32,12 +32,12 @@ export namespace Files { })).then( async modArr => { for ( const { name, mod, absPath } of modArr) { switch (mod.type) { - case 2 : Commands.set(name.substring(0, name.length-3), { mod, options: [] }); break; - case 4 : { + case 1 : Commands.set(name.substring(0, name.length-3), { mod, options: [] }); break; + case 2 : { const options = ((await import(absPath)).options as ApplicationCommandOptionData[]) Commands.set(name.substring(0, name.length - 3), { mod, options : options ?? [] }); } break; - case 2 | 4 : { + case 1 | 2 : { const options = ((await import(absPath)).options as ApplicationCommandOptionData[]) Commands.set(name.substring(0, name.length-3),{mod, options : options ?? [] } ); } break;