diff options
| author | seth <[email protected]> | 2023-07-10 00:18:36 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-11-16 00:35:07 +0000 |
| commit | a4a9353e1c8f902b7d7b3cf74e3e5b129c214330 (patch) | |
| tree | b58da1d30af52e97c0251e0d6882cd0ccdfeb20a /src/commands/bottom.rs | |
| parent | 5e9ec7f008e01d25c0b7f782c5ae043bc9ca0933 (diff) | |
start using poise
Diffstat (limited to 'src/commands/bottom.rs')
| -rw-r--r-- | src/commands/bottom.rs | 98 |
1 files changed, 35 insertions, 63 deletions
diff --git a/src/commands/bottom.rs b/src/commands/bottom.rs index dbe74b9..d38c4b8 100644 --- a/src/commands/bottom.rs +++ b/src/commands/bottom.rs @@ -1,70 +1,42 @@ -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, -}; +use crate::{Context, Error}; +use bottomify::bottom::{decode_string, encode_string}; -pub fn run(options: &[CommandDataOption]) -> String { - let err = "failed to get nested option in"; - - let data = options - .get(0) - .unwrap_or_else(|| panic!("{} {:?}", err, options)); +fn decode_sync(s: &str) -> Result<String, bottomify::bottom::TranslationError> { + decode_string(&s) +} - // get subcommand to decide whether to encode/decode - let subcommand = data.name.as_str(); +#[poise::command(slash_command, subcommands("encode", "decode"))] +pub async fn bottom(_ctx: Context<'_>) -> Result<(), Error> { + Ok(()) +} - // TODO: this is horrendous - // 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 +/// teawie will translate to bottom 🥺 +#[poise::command(slash_command)] +pub async fn encode( + ctx: Context<'_>, + #[description = "what teawie will translate into bottom"] message: String, +) -> Result<(), Error> { + let encoded = encode_string(&message); + ctx.say(encoded).await?; + Ok(()) +} - if let CommandDataOptionValue::String(msg) = option { - match subcommand { - "encode" => bottom_encode(msg), - "decode" => bottom_decode(msg), - _ => "something went wrong :(".to_owned(), +/// teawie will translate from bottom 🥸 +#[poise::command(slash_command)] +pub async fn decode( + ctx: Context<'_>, + #[description = "what teawie will translate from bottom"] message: String, +) -> Result<(), Error> { + let d = decode_sync(&message); + match d { + Ok(decoded) => { + ctx.say(decoded).await?; + Ok(()) + } + Err(why) => { + ctx.say("couldn't decode that for you, i'm sowwy!! :((".to_string()) + .await?; + Err(Box::new(why)) } - } else { - "did you forget to enter a message?".to_owned() } } - -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) - }) - }) -} |
