Add convert commands

This commit is contained in:
Xyon 2023-08-24 23:07:17 +01:00
parent 753192c13d
commit 66dee050a5
Signed by: xyon
GPG Key ID: DD18155D6B18078D
2 changed files with 100 additions and 0 deletions

98
src/commands/convert.rs Normal file
View File

@ -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<ManifoldData, ManifoldError>; 13] {
[convert(), ftoc(), ftok(), ftor(), ctof(), ctok(), ctor(), ktoc(), ktof(), ktor(), rtok(), rtoc(), rtof()]
}

View File

@ -1,5 +1,6 @@
mod admin;
mod frog;
mod convert;
mod core;
mod weather;
@ -9,6 +10,7 @@ pub fn collect_commands(injected: Vec<ManifoldCommand>) -> Vec<ManifoldCommand>
core::commands().into_iter()
.chain(admin::commands())
.chain(frog::commands())
.chain(convert::commands())
.chain(weather::commands())
.chain(injected)
.collect()