From 445822efad6682edbe0b1e27448b997fae9564c5 Mon Sep 17 00:00:00 2001 From: Leah Amelia Chen Date: Sun, 9 Jul 2023 18:38:31 -0600 Subject: Refactors + add pin board module (#32) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor according to the rules of the cone school of rustâ„¢ * Add pin board module * cargo fmt * More cleanups + appease clippy --- src/commands/convert.rs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/commands/convert.rs') 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 { -- cgit v1.2.3