From 954852104a318ff2e68ac71432c4994fddba3bae Mon Sep 17 00:00:00 2001 From: jacoobes Date: Wed, 26 Jan 2022 23:22:52 -0600 Subject: [PATCH] changing ret type of parse fn --- src/handler/sern/sern.ts | 11 +++++------ src/handler/utils/preprocessors/args.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/handler/sern/sern.ts b/src/handler/sern/sern.ts index e15e262..839d4fd 100644 --- a/src/handler/sern/sern.ts +++ b/src/handler/sern/sern.ts @@ -1,15 +1,14 @@ import type { MessagePackage, Visibility } from "../../types/handler/handler"; import { CommandType } from "../../types/handler/handler"; import { Files } from "../utils/readFile" -import type { Awaitable, Client, Message } from "discord.js"; +import type { Awaitable, Client, Message, Util } from "discord.js"; import type { possibleOutput } from "../../types/handler/handler" import { Err, Ok, Result } from "ts-results"; +import type { Utils } from "../utils/preprocessors/args"; export namespace Sern { - type Error = string; - export class Handler { private wrapper: Sern.Wrapper; private msgHandler : MsgHandler = new MsgHandler(); @@ -67,13 +66,13 @@ export namespace Sern { privateServerId : string } - export interface Module { + export interface Module { alias: string[], desc : string, visibility : Visibility, type: CommandType, - delegate : (message: Message, args: Ok ) => Awaitable | void> - parse? : (args: string) => Result + delegate : (message: Message, args: Ok ) => Awaitable | void> + parse? : (args: string) => Utils.ArgType } } diff --git a/src/handler/utils/preprocessors/args.ts b/src/handler/utils/preprocessors/args.ts index 29987d1..6640f92 100644 --- a/src/handler/utils/preprocessors/args.ts +++ b/src/handler/utils/preprocessors/args.ts @@ -6,7 +6,7 @@ export namespace Utils { /** * Wrapper type taking `Ok(T)` or `Err(possibleOutput)` e.g `Result = Result + export type ArgType = Result /** * * @param {string} arg @@ -38,6 +38,15 @@ export namespace Utils { } return Err(onFailure) } + /** + * + * @param {string} arg + * @param {string} sep + * @returns + */ + export function toArr(arg: string, sep: string) : ArgType { + return Ok(arg.split(sep)); + } }