silly goober bot
at main 46 lines 1.3 kB view raw
1use bottomify::bottom; 2use color_eyre::eyre::Result; 3 4use crate::types::Context; 5 6/// Translate your words for the bottoms to understand 7#[poise::command( 8 slash_command, 9 install_context = "Guild|User", 10 interaction_context = "Guild|BotDm|PrivateChannel" 11)] 12pub async fn bottomify(ctx: Context<'_>, #[description = "text"] input: String) -> Result<()> { 13 let out = bottom::encode_string(&input); 14 15 ctx.say(format!("```{out}```")).await?; 16 Ok(()) 17} 18 19/// Translate your words for the tops and normies to understand 20#[poise::command( 21 slash_command, 22 install_context = "Guild|User", 23 interaction_context = "Guild|BotDm|PrivateChannel" 24)] 25pub async fn topify(ctx: Context<'_>, #[description = "text"] input: String) -> Result<()> { 26 const MAX_LEN: usize = 1994; 27 const WRAP: &str = "```"; 28 let out = bottom::decode_string(&input); 29 30 if let Ok(out) = out { 31 let mut out = out.as_str(); 32 let len = out.len(); 33 for _ in 0..(len / MAX_LEN) { 34 let (x, xs) = out.split_at(MAX_LEN); 35 ctx.say(format!("{WRAP}{x}{WRAP}")).await?; 36 out = xs; 37 } 38 if len % MAX_LEN != 0 { 39 ctx.say(format!("{WRAP}{out}{WRAP}")).await?; 40 } 41 } else { 42 ctx.say("I couldn't decode that message.").await?; 43 } 44 45 Ok(()) 46}