added arg preprocessors

This commit is contained in:
jacoobes
2022-01-26 13:02:04 -06:00
parent ee72124a80
commit 5a729b635d
3 changed files with 25 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
import { Err, Ok, Result } from "ts-results";
import type { possibleOutput } from "../../../types/handler/handler";
export namespace Utils {
/**
* Wrapper type taking `Ok(T)` or `Err(possibleOutput)` e.g `Result<T, possibleOutput`
*/
type ArgType<T> = Result<T, possibleOutput>
/**
*
* @param {string} arg
* @param {possibleOutput} onFailure
* @returns {ArgType<number>} Attempts to use Number.parseInt() on `arg`
*/
export function parseInt(arg: string, onFailure: possibleOutput): ArgType<number> {
const val = Number.parseInt(arg);
return val === NaN ? Err(onFailure) : Ok(val);
}
}

View File

@@ -1,4 +1,5 @@
import { Sern } from "./handler/sern/sern";
module.exports = Sern;
export default Sern;

View File

@@ -1,7 +1,7 @@
import type { Ok, Result } from 'ts-results';
import type { Awaitable, Client, Message, MessagePayload} from 'discord.js';
import type { MessageOptions } from 'child_process';
import type Sern from '../..';
import type { Sern } from '../../handler/sern/sern';
export type Visibility = "private" | "public"
export type possibleOutput = string | MessagePayload & MessageOptions