aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2024-08-06 21:11:16 -0400
committerNathan Perry <np@nathanperry.dev>2024-08-06 21:18:31 -0400
commit96c197bde0f83d8b99ec66238856c76b41bfd5e1 (patch)
tree61f079dbd8a2e5a6d715ab2873a4a8ff7aff6bd7
parent0cc56bc18db7bb0818fbbbc1c8db670dd039c718 (diff)
fix long memers
-rw-r--r--Cargo.lock3
-rw-r--r--Cargo.toml3
-rw-r--r--src/commands/meme/history.rs28
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 <np@npry.dev>"]
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::<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(())
}