changing ret type of parse fn

This commit is contained in:
jacoobes
2022-01-26 23:22:52 -06:00
parent 9c0fffe1ac
commit 954852104a
2 changed files with 15 additions and 7 deletions

View File

@@ -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<Args> {
export interface Module<T> {
alias: string[],
desc : string,
visibility : Visibility,
type: CommandType,
delegate : (message: Message, args: Ok<Args> ) => Awaitable<Result<possibleOutput, string > | void>
parse? : (args: string) => Result<Args, Error>
delegate : (message: Message, args: Ok<T> ) => Awaitable<Result<possibleOutput, string > | void>
parse? : (args: string) => Utils.ArgType<T>
}
}

View File

@@ -6,7 +6,7 @@ export namespace Utils {
/**
* Wrapper type taking `Ok(T)` or `Err(possibleOutput)` e.g `Result<T, possibleOutput`
*/
type ArgType<T> = Result<T, possibleOutput>
export type ArgType<T> = Result<T, possibleOutput>
/**
*
* @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<string[]> {
return Ok(arg.split(sep));
}
}