From 66dee050a52b80ec7e606608739f08cd29d00ae9 Mon Sep 17 00:00:00 2001 From: Xyon Date: Thu, 24 Aug 2023 23:07:17 +0100 Subject: [PATCH] Add convert commands --- src/commands/convert.rs | 98 +++++++++++++++++++++++++++++++++++++++++ src/commands/mod.rs | 2 + 2 files changed, 100 insertions(+) create mode 100644 src/commands/convert.rs diff --git a/src/commands/convert.rs b/src/commands/convert.rs new file mode 100644 index 0000000..6bceea7 --- /dev/null +++ b/src/commands/convert.rs @@ -0,0 +1,98 @@ +use crate::error::{ManifoldError, ManifoldResult}; +use crate::{ManifoldContext, ManifoldData}; + +#[poise::command(slash_command, prefix_command, aliases("c"), subcommands("ftoc", "ftok", "ftor", "ctof", "ctok", "ctor", "rtof", "rtoc", "rtok", "ktoc", "ktof", "ktor"))] +pub async fn convert(ctx: ManifoldContext<'_>) -> ManifoldResult<()> { + + ctx.send(|f| f.content("Specify a conversion. See help for more info").reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ftoc(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°F is {}°C", value, ((value - 32.0)/1.8))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ftok(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°F is {}°K", value, (((value - 32.0)/1.8) + 273.0))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ftor(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°F is {}°R", value, (value + 459.67))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ctof(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°C is {}°F", value, ((value * 1.8)+32.0))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ctok(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°C is {}°K", value, (value + 273.15))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ctor(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°C is {}°R", value, ((value + 273.15) * (9.0/5.0)))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ktoc(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°K is {}°C", value, (value - 273.15))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ktof(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°K is {}°F", value, ((value * (9.0/5.0)) - 459.67))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn ktor(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°K is {}°R", value, (value * (9.0/5.0)))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn rtok(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°R is {}°K", value, (value * (5.0/9.0)))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn rtoc(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°R is {}°C", value, ((value - 491.67) * (5.0/9.0)))).reply(true)).await?; + + Ok(()) +} + +#[poise::command(slash_command, prefix_command)] +pub async fn rtof(ctx: ManifoldContext<'_>, value: f32) -> ManifoldResult<()> { + ctx.send(|f| f.content(format!("{}°R is {}°F", value, (value - 459.67))).reply(true)).await?; + + Ok(()) +} + +pub fn commands() -> [poise::Command; 13] { + [convert(), ftoc(), ftok(), ftor(), ctof(), ctok(), ctor(), ktoc(), ktof(), ktor(), rtok(), rtoc(), rtof()] +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b843b2d..471701d 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,5 +1,6 @@ mod admin; mod frog; +mod convert; mod core; mod weather; @@ -9,6 +10,7 @@ pub fn collect_commands(injected: Vec) -> Vec core::commands().into_iter() .chain(admin::commands()) .chain(frog::commands()) + .chain(convert::commands()) .chain(weather::commands()) .chain(injected) .collect()