From a84d4fd869787467d2284f23343244566bee1220 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Fri, 21 May 2021 22:40:03 +0000 Subject: [PATCH] Make command parsing case insensitive. --- src/commands/parser.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/commands/parser.rs b/src/commands/parser.rs index de96022..8ff52ba 100644 --- a/src/commands/parser.rs +++ b/src/commands/parser.rs @@ -129,7 +129,7 @@ fn split_command(input: &str) -> Result<(String, String), CommandParsingError> { /// we don't recognize the command, return an error. pub fn parse_command(input: &str) -> Result, BotError> { match split_command(input) { - Ok((cmd, cmd_input)) => match cmd.as_ref() { + Ok((cmd, cmd_input)) => match cmd.to_lowercase().as_ref() { "variables" => get_all_variables(), "get" => parse_get_variable_command(&cmd_input), "set" => parse_set_variable_command(&cmd_input), @@ -137,10 +137,8 @@ pub fn parse_command(input: &str) -> Result, BotError> { "resync" => parse_resync(), "r" | "roll" => parse_roll(&cmd_input), "rp" | "pool" => parse_pool_roll(&cmd_input), - "cthroll" | "cthRoll" => parse_cth_roll(&cmd_input), - "cthadv" | "ctharoll" | "cthAroll" | "cthARoll" => { - parse_cth_advancement_roll(&cmd_input) - } + "cthroll" => parse_cth_roll(&cmd_input), + "cthadv" | "ctharoll" => parse_cth_advancement_roll(&cmd_input), "chance" => chance_die(), "help" => help(&cmd_input), _ => Err(CommandParsingError::UnrecognizedCommand(cmd).into()), @@ -290,4 +288,9 @@ mod tests { parse_command("!roll 1d4 + 5d6 -3 ").expect("was error"); parse_command(" !roll 1d4 + 5d6 -3 ").expect("was error"); } + + #[test] + fn case_insensitive_test() { + parse_command("!CTHROLL 40").expect("command parsing is not case sensitive."); + } }