diff options
Diffstat (limited to 'src/commands')
| -rw-r--r-- | src/commands/convert.rs | 68 | ||||
| -rw-r--r-- | src/commands/copypasta.rs | 2 | ||||
| -rw-r--r-- | src/commands/mod.rs | 1 |
3 files changed, 70 insertions, 1 deletions
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; |
