summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore6
-rw-r--r--src/commands/convert.rs68
-rw-r--r--src/commands/copypasta.rs2
-rw-r--r--src/commands/mod.rs1
-rw-r--r--src/main.rs2
-rw-r--r--src/utils.rs14
6 files changed, 92 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 5b6ba37..4206ea8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,9 @@ result
# mac stuff (you're welcome sake)
**/.DS_Store
+
+# ide stuf
+.idea/
+.vs/
+.vscode/
+
diff --git a/src/commands/convert.rs b/src/commands/convert.rs
new file mode 100644
index 0000000..6fe141d
--- /dev/null
+++ b/src/commands/convert.rs
@@ -0,0 +1,68 @@
+use crate::utils;
+use serenity::builder::CreateApplicationCommand;
+use serenity::model::prelude::command::CommandOptionType;
+use serenity::model::prelude::interaction::application_command::{
+ CommandDataOption, CommandDataOptionValue,
+};
+
+pub async fn run(options: &[CommandDataOption]) -> String {
+ let err = "couldn't get convert subcommand!";
+ let data = options
+ .get(0)
+ .unwrap_or_else(|| panic!("{} {:?}", err, options));
+ let subcommand = data.name.as_str();
+ // get message content
+ let option = data
+ .options
+ .get(0)
+ .unwrap_or_else(|| panic!("{} {:?}", err, data))
+ .resolved
+ .as_ref()
+ .expect("failed to resolve string!");
+
+ let mut ret = 0.0;
+ if let CommandDataOptionValue::Number(number) = option {
+ match subcommand {
+ "fahrenheit" => ret = utils::celsius_to_fahrenheit(number).await,
+ "celsius" => ret = utils::fahrenheit_to_celsius(number).await,
+ _ => ret = 0.0,
+ };
+ };
+
+ if ret == 0.0 {
+ return "couldn't figure it out oops".to_string();
+ }
+ format!("{:.2}", ret)
+}
+
+pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
+ command
+ .name("convertto")
+ .description("ask teawie to convert something for you")
+ .create_option(|option| {
+ option
+ .name("fahrenheit")
+ .description("ask teawie to convert celsius to fahrenheit")
+ .kind(CommandOptionType::SubCommand)
+ .create_sub_option(|suboption| {
+ suboption
+ .name("degrees_celsius")
+ .description("what teawie will convert")
+ .kind(CommandOptionType::Number)
+ .required(true)
+ })
+ })
+ .create_option(|option| {
+ option
+ .name("celsius")
+ .description("ask teawie to convert fahrenheit to celsius")
+ .kind(CommandOptionType::SubCommand)
+ .create_sub_option(|suboption| {
+ suboption
+ .name("degrees_fahrenheit")
+ .description("what teawie will convert")
+ .kind(CommandOptionType::Number)
+ .required(true)
+ })
+ })
+}
diff --git a/src/commands/copypasta.rs b/src/commands/copypasta.rs
index 20ca144..ec3f3c6 100644
--- a/src/commands/copypasta.rs
+++ b/src/commands/copypasta.rs
@@ -9,7 +9,7 @@ use serenity::model::prelude::interaction::application_command::{
use std::sync::Arc;
pub async fn run(options: &[CommandDataOption], channel_id: ChannelId, http: &Arc<Http>) -> String {
- let err_msg = "expected a copyasta";
+ let err_msg = "expected a copypasta";
let option = options
.get(0)
.expect(err_msg)
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 3bda3ac..fb7ee4b 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,5 +1,6 @@
pub mod ask;
pub mod bottom;
+pub mod convert;
pub mod copypasta;
pub mod random_lore;
pub mod random_teawie;
diff --git a/src/main.rs b/src/main.rs
index 22a71db..af47e6b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -72,6 +72,7 @@ impl EventHandler for Handler {
let content = match command.data.name.as_str() {
"ask" => commands::ask::run(&command.data.options).await,
"bottom" => commands::bottom::run(&command.data.options).await,
+ "convertto" => commands::convert::run(&command.data.options).await,
"copypasta" => {
commands::copypasta::run(&command.data.options, command.channel_id, &ctx.http)
.await
@@ -110,6 +111,7 @@ impl EventHandler for Handler {
commands
.create_application_command(|command| commands::ask::register(command))
.create_application_command(|command| commands::bottom::register(command))
+ .create_application_command(|command| commands::convert::register(command))
.create_application_command(|command| commands::random_lore::register(command))
.create_application_command(|command| commands::random_teawie::register(command))
})
diff --git a/src/utils.rs b/src/utils.rs
index 4b56dc6..2713241 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -98,3 +98,17 @@ pub async fn bottom_decode(msg: &str) -> String {
}
}
}
+
+/*
+ * converts celsius to fahrenheit
+ */
+pub async fn celsius_to_fahrenheit(c: &f64) -> f64 {
+ (c * (9.0 / 5.0)) + 32.0
+}
+
+/*
+ * converts fahrenheit to celsius
+ */
+pub async fn fahrenheit_to_celsius(f: &f64) -> f64 {
+ (f - 32.0) * (5.0 / 9.0)
+}