silly goober bot

fix(commands/bottom): split message at length limit

authored by

Kaitlyn~Ethylia and committed by isabelroses.com 3cbacecb 3c2bd7ee

+13 -2
+13 -2
src/commands/fun/bottom.rs
··· 15 15 /// Translate your words for the tops and normies to understand 16 16 #[poise::command(slash_command, guild_only)] 17 17 pub async fn topify(ctx: Context<'_>, #[description = "text"] input: String) -> Result<()> { 18 + const MAX_LEN: usize = 1994; 19 + const WRAP: &'static str = "```"; 18 20 let out = bottom::decode_string(&input); 19 21 20 - if out.is_ok() { 21 - ctx.say(out?).await?; 22 + if let Ok(out) = out { 23 + let mut out = out.as_str(); 24 + let len = out.len(); 25 + for _ in 0..(len / MAX_LEN) { 26 + let (x, xs) = out.split_at(MAX_LEN); 27 + ctx.say(format!("{WRAP}{x}{WRAP}")).await?; 28 + out = xs; 29 + } 30 + if len % MAX_LEN != 0 { 31 + ctx.say(format!("{WRAP}{out}{WRAP}")).await?; 32 + } 22 33 } else { 23 34 ctx.say("I couldn't decode that message.").await?; 24 35 }