diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-10-14 04:44:26 +0200 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-10-14 04:44:26 +0200 |
| commit | bea4d2a63b15eb3f908d8612bdc94dca1829229f (patch) | |
| tree | 092df4a97b7636149dc57f58732b251eb006bf26 | |
| parent | ee1e7dfae96af5a426176f396ca3a23706033c45 (diff) | |
| download | frippy-bea4d2a63b15eb3f908d8612bdc94dca1829229f.tar.gz frippy-bea4d2a63b15eb3f908d8612bdc94dca1829229f.zip | |
Improve readability of the Currency plugin
| -rw-r--r-- | src/plugins/currency.rs | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/plugins/currency.rs b/src/plugins/currency.rs index bb16cd9..c6f0b2f 100644 --- a/src/plugins/currency.rs +++ b/src/plugins/currency.rs @@ -82,6 +82,11 @@ impl Currency { } fn convert(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> { + + if command.tokens.len() < 3 { + return self.invalid_command(server, &command); + } + let request = match self.eval_command(&command.tokens) { Some(request) => request, None => { @@ -103,7 +108,7 @@ impl Currency { } } - fn help(&self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> { + fn help(&self, server: &IrcServer, command: &mut PluginCommand) -> Result<(), IrcError> { let help = format!("usage: {} currency value from_currency to_currency\r\n\ example: 1.5 eur usd\r\n\ available currencies: AUD, BGN, BRL, CAD, \ @@ -117,7 +122,7 @@ impl Currency { } fn invalid_command(&self, server: &IrcServer, command: &PluginCommand) -> Result<(), IrcError> { - let help = format!("Incorrect value. \ + let help = format!("Incorrect Command. \ Send \"{} help currency\" for help.", server.current_nickname()); @@ -134,18 +139,15 @@ impl Plugin for Currency { Ok(()) } - fn command(&mut self, server: &IrcServer, command: PluginCommand) -> Result<(), IrcError> { - if command.tokens.is_empty() { - self.invalid_command(server, &command) + fn command(&mut self, server: &IrcServer, mut command: PluginCommand) -> Result<(), IrcError> { - } else if command.tokens[0].to_lowercase() == "help" { - self.help(server, command) - - } else if command.tokens.len() >= 3 { - self.convert(server, command) + if command.tokens.is_empty() { + return self.invalid_command(server, &command); + } - } else { - self.invalid_command(server, &command) + match command.tokens[0].as_ref() { + "help" => self.help(server, &mut command), + _ => self.convert(server, command), } } } |
