From bdfc1ed233bfa9b6b27e7b7c470ae682f46dd128 Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Fri, 18 Aug 2023 16:45:19 -0300 Subject: [PATCH] chunk very large messages because discord has a silly little limit --- src/handlers/llama.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/handlers/llama.rs b/src/handlers/llama.rs index 38be5d9..3686aac 100644 --- a/src/handlers/llama.rs +++ b/src/handlers/llama.rs @@ -4,6 +4,7 @@ use crate::config::LlamaConfig; use super::LineHandler; +use itertools::Itertools; use reqwest_streams::*; use serde::{Deserialize, Serialize}; use serenity::{ @@ -108,8 +109,16 @@ impl LineHandler for LlamaHandler { resp }; - if let Err(e) = msg.reply(ctx, resp).await { - eprintln!("{e:?}"); + let chunks: Vec<String> = resp + .chars() + .chunks(2000) + .into_iter() + .map(|chunk| chunk.collect()) + .collect(); + for chunk in chunks { + if let Err(e) = msg.reply(ctx, chunk).await { + eprintln!("{e:?}"); + } } return; -- GitLab