summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseth <[email protected]>2023-04-07 22:59:35 -0400
committerseth <[email protected]>2023-04-07 23:13:40 -0400
commit0d0e68fec058b7a8b8e9a4768a183ec08ffad770 (patch)
tree6f78cde40cf569a360b7dcce285417e9072e69dc
parent065ac97194b7640ca350b4770b404d855bf98b17 (diff)
add bottom subcommands
-rw-r--r--src/commands/bottom.rs76
-rw-r--r--src/commands/bottom_decode.rs35
-rw-r--r--src/commands/bottom_encode.rs35
-rw-r--r--src/commands/mod.rs3
-rw-r--r--src/main.rs6
-rw-r--r--src/utils.rs14
6 files changed, 86 insertions, 83 deletions
diff --git a/src/commands/bottom.rs b/src/commands/bottom.rs
new file mode 100644
index 0000000..d25eab1
--- /dev/null
+++ b/src/commands/bottom.rs
@@ -0,0 +1,76 @@
+use crate::utils::{bottom_decode, bottom_encode};
+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 = "failed to get nested option in";
+ let mut ret = "did you forget to enter a message?".to_string();
+
+ let data = options
+ .get(0)
+ .unwrap_or_else(|| panic!("{} {:?}", err, options));
+
+ // get subcommand to decide whether to encode/decode
+ 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!"); // this is annoying
+
+ if let CommandDataOptionValue::String(msg) = option {
+ match subcommand {
+ "encode" => {
+ ret = bottom_encode(msg).await;
+ }
+ "decode" => {
+ ret = bottom_decode(msg).await;
+ }
+ _ => {
+ ret = "something went wrong :(".to_string();
+ }
+ };
+ }
+
+ ret
+}
+
+pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicationCommand {
+ command
+ .name("bottom")
+ .description("teawie will translate something to/from bottom for you 🥺")
+ // nesting...so much nesting
+ .create_option(|option| {
+ option
+ .name("encode")
+ .description("teawie will encode a message in bottom for you 🥺")
+ .kind(CommandOptionType::SubCommand)
+ .create_sub_option(|suboption| {
+ suboption
+ .name("content")
+ .description("what teawie will translate into bottom")
+ .kind(CommandOptionType::String)
+ .required(true)
+ })
+ })
+ .create_option(|option| {
+ option
+ .name("decode")
+ .description("teawie will decode a message in bottom for you 🥸")
+ .kind(CommandOptionType::SubCommand)
+ .create_sub_option(|suboption| {
+ suboption
+ .name("content")
+ .description("what teawie will translate from bottom")
+ .kind(CommandOptionType::String)
+ .required(true)
+ })
+ })
+}
diff --git a/src/commands/bottom_decode.rs b/src/commands/bottom_decode.rs
deleted file mode 100644
index fb91756..0000000
--- a/src/commands/bottom_decode.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-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
deleted file mode 100644
index 741adc7..0000000
--- a/src/commands/bottom_encode.rs
+++ /dev/null
@@ -1,35 +0,0 @@
-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 afe1e39..3bda3ac 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -1,6 +1,5 @@
pub mod ask;
-pub mod bottom_decode;
-pub mod bottom_encode;
+pub mod bottom;
pub mod copypasta;
pub mod random_lore;
pub mod random_teawie;
diff --git a/src/main.rs b/src/main.rs
index e5b9bb9..fac587a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -56,8 +56,7 @@ 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,
+ "bottom" => commands::bottom::run(&command.data.options).await,
"copypasta" => {
commands::copypasta::run(&command.data.options, command.channel_id, &ctx.http)
.await
@@ -88,8 +87,7 @@ 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::bottom::register(command))
.create_application_command(|command| commands::copypasta::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 78e02dd..c75601f 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -79,21 +79,21 @@ pub async fn get_copypasta(name: &str) -> Vec<String> {
}
/*
- * encodes a string into bottom 🥺
+ * encodes a message into bottom
*/
-pub async fn bottom_encode(string: &str) -> String {
- encode_string(&string)
+pub async fn bottom_encode(msg: &str) -> String {
+ encode_string(&msg)
}
/*
- * decodes a bottom string into english 🥸
+ * decodes a bottom string into english
*/
-pub async fn bottom_decode(string: &str) -> String {
- let decoded = decode_string(&string);
+pub async fn bottom_decode(msg: &str) -> String {
+ let decoded = decode_string(&msg);
match decoded {
Ok(ret) => ret,
Err(why) => {
- println!("couldn't decode {:?}! ({:?})", string, why);
+ println!("couldn't decode {:?}! ({:?})", msg, why);
"couldn't decode that! sowwy 🥺".to_string()
}
}