fixed parseBool function

This commit is contained in:
jacoobes
2022-01-29 08:47:48 -06:00
parent a5c52ab483
commit 9ac7ef24b4
2 changed files with 5 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ export namespace Sern {
return "This command is not availible in this guild!"
}
if (module.type === CommandType.SLASH) return `This may be a slash command and not a legacy command`
let args = this.msgHandler.fmtMsg.slice(1).join(" ");
let args = this.msgHandler.fmtMsg.join(" ");
let parsedArgs = module.parse === undefined ? Ok("") : module.parse(message, args);
if(parsedArgs.err) return parsedArgs.val;
let fn = await module.delegate(message, parsedArgs)

View File

@@ -21,15 +21,14 @@ export namespace Utils {
*
* @param {string} arg - command arguments
* @param {possibleOutput} onFailure - If cannot parse `arg` into boolean.
* @param { {yesRegex: RegExp, noRegex: RegExp} } regexes - default regexes: yes : `/(yes|y|👍)/gi`, no : /(no|n|👎)/gi
* @param { {yesRegex: RegExp, noRegex: RegExp} } regexes - default regexes: yes : `/^(?:y(?:es)?|👍)$/i`, no : /^(?:n(?:o)?|👎)$/i
* @returns { ArgType<boolean> } attemps to parse `args` as a boolean
*/
export function parseBool(
arg: string,
onFailure: possibleOutput = `Cannot parse ${arg} as a boolean`,
regexes : {yesRegex: RegExp, noRegex: RegExp} = {yesRegex : /(yes|y|👍)/gi, noRegex : /(no|n|👎)/gi}
onFailure: possibleOutput = `Cannot parse "${arg}" as a boolean`,
regexes : {yesRegex: RegExp, noRegex: RegExp} = { yesRegex : /^(?:y(?:es)?|👍)$/i , noRegex : /^(?:n(?:o)?|👎)$/i }
): ArgType<boolean> {
if(arg.match(regexes.yesRegex)) return Ok(true);
if(arg.match(regexes.noRegex)) return Ok(false);
return Err(onFailure);
@@ -51,7 +50,7 @@ export namespace Utils {
* @returns {ArgType<number>}
*/
export function toPositiveInt(arg: string, onFailure: possibleOutput) : ArgType<number> {
return Utils.parseInt(arg, onFailure).andThen( num => Ok(num > 0 ? num : Math.abs(num)))
return Utils.parseInt(arg, onFailure).andThen( num => Ok(num > 0 ? num :-num))
}
/**