diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/bottom_decode.rs | 35 | ||||
| -rw-r--r-- | src/commands/bottom_encode.rs | 35 | ||||
| -rw-r--r-- | src/commands/mod.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 4 | ||||
| -rw-r--r-- | src/utils.rs | 22 |
5 files changed, 98 insertions, 0 deletions
diff --git a/src/commands/bottom_decode.rs b/src/commands/bottom_decode.rs new file mode 100644 index 0000000..fb91756 --- /dev/null +++ b/src/commands/bottom_decode.rs @@ -0,0 +1,35 @@ +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_msg = "expected a copyasta"; + let option = options + .get(0) + .expect(err_msg) + .resolved + .as_ref() + .expect(err_msg); + + if let CommandDataOptionValue::String(msg) = option { + return utils::bottom_decode(msg).await; + } + + "did you forget to enter a message?".to_string() +} + +pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { + command + .name("bottom_decode") + .description("teawie will translate something from bottom for you 🥺") + .create_option(|option| { + option + .name("message") + .description("what you want teawie to translate") + .kind(CommandOptionType::String) + .required(true) + }) +} diff --git a/src/commands/bottom_encode.rs b/src/commands/bottom_encode.rs new file mode 100644 index 0000000..741adc7 --- /dev/null +++ b/src/commands/bottom_encode.rs @@ -0,0 +1,35 @@ +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_msg = "expected a copyasta"; + let option = options + .get(0) + .expect(err_msg) + .resolved + .as_ref() + .expect(err_msg); + + if let CommandDataOptionValue::String(msg) = option { + return utils::bottom_encode(msg).await; + } + + "did you forget to enter a message?".to_string() +} + +pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand { + command + .name("bottom_encode") + .description("teawie will translate something to bottom for you 🥺") + .create_option(|option| { + option + .name("message") + .description("what you want teawie to translate") + .kind(CommandOptionType::String) + .required(true) + }) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d3ec259..7005ae2 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,5 @@ pub mod ask; +pub mod bottom_decode; +pub mod bottom_encode; pub mod copypasta; pub mod random_teawie; diff --git a/src/main.rs b/src/main.rs index 89a686c..1d39fa5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,6 +56,8 @@ impl EventHandler for Handler { println!("Received command interaction: {:#?}", command); let content = match command.data.name.as_str() { "ask" => commands::ask::run(&command.data.options).await, + "bottom_decode" => commands::bottom_decode::run(&command.data.options).await, + "bottom_encode" => commands::bottom_encode::run(&command.data.options).await, "copypasta" => { commands::copypasta::run(&command.data.options, command.channel_id, &ctx.http) .await @@ -85,6 +87,8 @@ impl EventHandler for Handler { let commands = GuildId::set_application_commands(&guild_id, &ctx.http, |commands| { commands .create_application_command(|command| commands::ask::register(command)) + .create_application_command(|command| commands::bottom_decode::register(command)) + .create_application_command(|command| commands::bottom_encode::register(command)) .create_application_command(|command| commands::random_teawie::register(command)) .create_application_command(|command| commands::copypasta::register(command)) }) diff --git a/src/utils.rs b/src/utils.rs index db5a5c4..4157e3b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,5 @@ use crate::consts::*; +use bottomify::bottom::{decode_string, encode_string}; use include_dir::{include_dir, Dir}; use rand::seq::SliceRandom; use std::collections::HashMap; @@ -65,3 +66,24 @@ pub async fn get_copypasta(name: &str) -> Vec<String> { let err = format!("couldn't find {:?} in files", name); vec![err] } + +/* + * encodes a string into bottom 🥺 + */ +pub async fn bottom_encode(string: &str) -> String { + encode_string(&string) +} + +/* + * decodes a bottom string into english 🥸 + */ +pub async fn bottom_decode(string: &str) -> String { + let decoded = decode_string(&string); + match decoded { + Ok(ret) => ret, + Err(why) => { + println!("couldn't decode {:?}! ({:?})", string, why); + "couldn't decode that! sowwy 🥺".to_string() + } + } +} |
