diff options
| author | Leah Amelia Chen <[email protected]> | 2023-07-09 18:38:31 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-09 20:38:31 -0400 |
| commit | 445822efad6682edbe0b1e27448b997fae9564c5 (patch) | |
| tree | f95ffa8dac7845e9ee42a1a686c6e627e5a08195 /src/commands/convert.rs | |
| parent | 9b65da1265b3d6f5d38382012e6abc3936b8a45f (diff) | |
Refactors + add pin board module (#32)
* refactor according to the rules of the cone school of rustâ„¢
* Add pin board module
* cargo fmt
* More cleanups + appease clippy
Diffstat (limited to 'src/commands/convert.rs')
| -rw-r--r-- | src/commands/convert.rs | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/commands/convert.rs b/src/commands/convert.rs index 6fe141d..8f8c424 100644 --- a/src/commands/convert.rs +++ b/src/commands/convert.rs @@ -5,7 +5,7 @@ use serenity::model::prelude::interaction::application_command::{ CommandDataOption, CommandDataOptionValue, }; -pub async fn run(options: &[CommandDataOption]) -> String { +pub fn run(options: &[CommandDataOption]) -> String { let err = "couldn't get convert subcommand!"; let data = options .get(0) @@ -20,19 +20,21 @@ pub async fn run(options: &[CommandDataOption]) -> String { .as_ref() .expect("failed to resolve string!"); - let mut ret = 0.0; - if let CommandDataOptionValue::Number(number) = option { + let temp = if let &CommandDataOptionValue::Number(number) = option { match subcommand { - "fahrenheit" => ret = utils::celsius_to_fahrenheit(number).await, - "celsius" => ret = utils::fahrenheit_to_celsius(number).await, - _ => ret = 0.0, - }; + "fahrenheit" => Some(utils::celsius_to_fahrenheit(number)), + "celsius" => Some(utils::fahrenheit_to_celsius(number)), + _ => None, + } + } else { + None }; - if ret == 0.0 { - return "couldn't figure it out oops".to_string(); + if let Some(temp) = temp { + format!("{temp:.2}") + } else { + "couldn't figure it out oops".to_owned() } - format!("{:.2}", ret) } pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { |
