diff options
| author | seth <[email protected]> | 2023-11-30 22:18:51 -0500 |
|---|---|---|
| committer | seth <[email protected]> | 2023-12-01 07:12:49 -0500 |
| commit | 76c0f94e6d7aa108424b34826eb7d8514b026287 (patch) | |
| tree | 7315bd6dfe52c158041bed64ba39781718a69335 /src/commands/convert.rs | |
| parent | db52e639b85d79bed870020aec7a045851ca5ee3 (diff) | |
feat: use eyre, better logging, & refactor
small commits be damned
Diffstat (limited to 'src/commands/convert.rs')
| -rw-r--r-- | src/commands/convert.rs | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/commands/convert.rs b/src/commands/convert.rs index 1f39ae4..cbbf8dc 100644 --- a/src/commands/convert.rs +++ b/src/commands/convert.rs @@ -1,11 +1,13 @@ -use crate::{Context, Error}; +use crate::Context; + use bottomify::bottom; +use color_eyre::eyre::Result; #[poise::command( slash_command, subcommands("to_fahrenheit", "to_celsius", "to_bottom", "from_bottom") )] -pub async fn convert(_ctx: Context<'_>) -> Result<(), Error> { +pub async fn convert(_ctx: Context<'_>) -> Result<()> { Ok(()) } @@ -14,7 +16,7 @@ pub async fn convert(_ctx: Context<'_>) -> Result<(), Error> { pub async fn to_celsius( ctx: Context<'_>, #[description = "what teawie will convert"] degrees_fahrenheit: f32, -) -> Result<(), Error> { +) -> Result<()> { let temp = (degrees_fahrenheit - 32.0) * (5.0 / 9.0); ctx.say(temp.to_string()).await?; Ok(()) @@ -25,7 +27,7 @@ pub async fn to_celsius( pub async fn to_fahrenheit( ctx: Context<'_>, #[description = "what teawie will convert"] degrees_celsius: f32, -) -> Result<(), Error> { +) -> Result<()> { let temp = (degrees_celsius * (9.0 / 5.0)) + 32.0; ctx.say(temp.to_string()).await?; Ok(()) @@ -36,7 +38,7 @@ pub async fn to_fahrenheit( pub async fn to_bottom( ctx: Context<'_>, #[description = "what teawie will translate into bottom"] message: String, -) -> Result<(), Error> { +) -> Result<()> { let encoded = bottom::encode_string(&message); ctx.say(encoded).await?; Ok(()) @@ -47,17 +49,8 @@ pub async fn to_bottom( pub async fn from_bottom( ctx: Context<'_>, #[description = "what teawie will translate from bottom"] message: String, -) -> Result<(), Error> { - let d = bottom::decode_string(&message); - match d { - Ok(decoded) => { - ctx.say(decoded).await?; - Ok(()) - } - Err(why) => { - ctx.say("couldn't decode that for you, i'm sowwy!! :((".to_string()) - .await?; - Err(Box::new(why)) - } - } +) -> Result<()> { + let decoded = bottom::decode_string(&message)?; + ctx.say(decoded).await?; + Ok(()) } |
