diff options
| author | Nathan Perry <np@nathanperry.dev> | 2024-08-06 21:11:16 -0400 |
|---|---|---|
| committer | Nathan Perry <np@nathanperry.dev> | 2024-08-06 21:18:31 -0400 |
| commit | 96c197bde0f83d8b99ec66238856c76b41bfd5e1 (patch) | |
| tree | 61f079dbd8a2e5a6d715ab2873a4a8ff7aff6bd7 /src | |
| parent | 0cc56bc18db7bb0818fbbbc1c8db670dd039c718 (diff) | |
fix long memers
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/meme/history.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index 9651ba1..68416e5 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -300,11 +300,31 @@ pub async fn memers(ctx: PoiseContext<'_>) -> anyhow::Result<()> { anyhow::Ok(res) }) .try_collect::<Vec<String>>() - .await? - .into_iter() - .join("\n"); + .await?; - util::reply(ctx, s).await?; + let mut out = String::new(); + + for line in s { + if line.len() >= 2000 { + anyhow::bail!("singular line too long"); + } + + if out.len() + line.len() >= 2000 { + let result = out.trim_end_matches('\n'); + util::reply(ctx, &result).await?; + out.clear(); + } + + out.push_str(&line); + out.push('\n'); + } + + if !out.is_empty() { + let result = out.trim_end_matches('\n'); + util::reply(ctx, result).await?; + } else { + util::reply(ctx, "no memers :(").await?; + } Ok(()) } |
