summaryrefslogtreecommitdiff
path: root/src/commands/general/convert.rs
blob: a736ccf3c9e9578e3eb3acbad0b7d5e8a6121690 (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
64
65
66
67
68
69
70
use crate::client::Context;

use anyhow::Result;
use bottomify::bottom;
use poise::serenity_prelude::constants::MESSAGE_CODE_LIMIT;

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

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

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

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

/// Translate from bottom 🥸
#[poise::command(slash_command)]
pub async fn from_bottom(
	ctx: Context<'_>,
	#[description = "What to translate from bottom"] message: String,
) -> Result<()> {
	let resp: String;

	if let Ok(decoded) = bottom::decode_string(&message.clone()) {
		resp = if decoded.len() > MESSAGE_CODE_LIMIT {
			"The translation is too long to send, sorry :(".to_string()
		} else {
			decoded
		}
	} else {
		resp = "Couldn't translate that for you :(".to_string();
	}

	ctx.say(resp).await?;

	Ok(())
}