From 994ff11655e9719b302bcdd7569044a40091893a Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Wed, 26 Feb 2025 11:37:50 +0100 Subject: [PATCH] Attempting to simplify --- reginaldCog/reginald.py | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index ac9a321..31cbf00 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -647,36 +647,24 @@ class ReginaldCog(commands.Cog): return - chunks = [] + #chunks = [] while len(content) > 0: - # First, try to split at the nearest sentence-ending punctuation - split_index = max( - content.rfind(". ", 0, CHUNK_SIZE), - content.rfind("? ", 0, CHUNK_SIZE), - content.rfind("! ", 0, CHUNK_SIZE), - ) + # Find the nearest valid break point within CHUNK_SIZE + split_index = content[:CHUNK_SIZE].rfind("\n") - # If no sentence-ending punctuation found, fall back to newline + # If no newline, fall back to the nearest space if split_index == -1: - split_index = content.rfind("\n", 0, CHUNK_SIZE) + split_index = content[:CHUNK_SIZE].rfind(" ") - # If no newline found, fall back to word space - if split_index == -1: - split_index = content.rfind(" ", 0, CHUNK_SIZE) - - # If no good breaking point found, split at the max chunk size + # If still no valid break point, hard split at CHUNK_SIZE if split_index == -1: split_index = CHUNK_SIZE - # Extract chunk, ensuring we don't cut words or sentences - chunk = content[:split_index + 1].strip() - content = content[split_index + 1:].strip() # Trim the remaining content + # Extract the chunk and send it + chunk = content[:split_index].strip() + content = content[split_index:].strip() - chunks.append(chunk) - - # Send each chunk - for chunk in chunks: - await ctx.send(f"{prefix}{chunk}") + await ctx.send(f"{prefix}{chunk}") # Send the chunk async def setup(bot): """✅ Correct async cog setup for Redbot"""