From 96c197bde0f83d8b99ec66238856c76b41bfd5e1 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 6 Aug 2024 21:11:16 -0400 Subject: fix long memers --- Cargo.lock | 3 +-- Cargo.toml | 3 +-- src/commands/meme/history.rs | 28 ++++++++++++++++++++++++---- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2efc835..62136b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3008,7 +3008,7 @@ dependencies = [ [[package]] name = "thulani" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "chrono", @@ -3018,7 +3018,6 @@ dependencies = [ "diesel-async", "diesel_async_migrations", "dotenv", - "either", "envconfig", "envconfig_derive", "fern", diff --git a/Cargo.toml b/Cargo.toml index 3057c94..a4037c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "thulani" -version = "0.3.0" +version = "0.3.1" authors = ["Nathan Perry "] edition = "2021" default-run = "thulani" @@ -25,7 +25,6 @@ chrono = "0.4" time = "0.3" fern = { version = "0.6", features = ["colored"] } rand = "0.8" -either = "1.10" reqwest = { version = "0.11", features = ["json"] } sha1 = { version = "0.10", features = ["std"] } regex = "1.10" 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::>() - .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(()) } -- cgit v1.3.1