summaryrefslogtreecommitdiff
path: root/src/commands/convert.rs
blob: 4e5d71ccf8b5b20d263bfd7595167b0875a0ee1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::{Context, Error};
use bottomify::bottom::{decode_string, encode_string};

#[poise::command(
	slash_command,
	subcommands("to_fahrenheit", "to_celsius", "to_bottom", "from_bottom")
)]
pub async fn convert(_ctx: Context<'_>) -> Result<(), Error> {
	Ok(())
}

/// ask teawie to convert °F to °C
#[poise::command(slash_command)]
pub async fn to_celsius(
	ctx: Context<'_>,
	#[description = "what teawie will convert"] degrees_fahrenheit: f32,
) -> Result<(), Error> {
	let temp = (degrees_fahrenheit - 32.0) * (5.0 / 9.0);
	ctx.say(temp.to_string()).await?;
	Ok(())
}

/// ask teawie to convert °C to °F
#[poise::command(slash_command)]
pub async fn to_fahrenheit(
	ctx: Context<'_>,
	#[description = "what teawie will convert"] degrees_celsius: f32,
) -> Result<(), Error> {
	let temp = (degrees_celsius * (9.0 / 5.0)) + 32.0;
	ctx.say(temp.to_string()).await?;
	Ok(())
}

/// teawie will translate to bottom 🥺
#[poise::command(slash_command)]
pub async fn to_bottom(
	ctx: Context<'_>,
	#[description = "what teawie will translate into bottom"] message: String,
) -> Result<(), Error> {
	let encoded = encode_string(&message);
	ctx.say(encoded).await?;
	Ok(())
}

/// teawie will translate from bottom 🥸
#[poise::command(slash_command)]
pub async fn from_bottom(
	ctx: Context<'_>,
	#[description = "what teawie will translate from bottom"] message: String,
) -> Result<(), Error> {
	let d = 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))
		}
	}
}