Attempting to simplify

This commit is contained in:
AllfatherHatt 2025-02-26 11:37:50 +01:00
parent 678a7af77f
commit 994ff11655

View File

@ -647,36 +647,24 @@ class ReginaldCog(commands.Cog):
return return
chunks = [] #chunks = []
while len(content) > 0: while len(content) > 0:
# First, try to split at the nearest sentence-ending punctuation # Find the nearest valid break point within CHUNK_SIZE
split_index = max( split_index = content[:CHUNK_SIZE].rfind("\n")
content.rfind(". ", 0, CHUNK_SIZE),
content.rfind("? ", 0, CHUNK_SIZE),
content.rfind("! ", 0, CHUNK_SIZE),
)
# If no sentence-ending punctuation found, fall back to newline # If no newline, fall back to the nearest space
if split_index == -1: 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 still no valid break point, hard split at CHUNK_SIZE
if split_index == -1:
split_index = content.rfind(" ", 0, CHUNK_SIZE)
# If no good breaking point found, split at the max chunk size
if split_index == -1: if split_index == -1:
split_index = CHUNK_SIZE split_index = CHUNK_SIZE
# Extract chunk, ensuring we don't cut words or sentences # Extract the chunk and send it
chunk = content[:split_index + 1].strip() chunk = content[:split_index].strip()
content = content[split_index + 1:].strip() # Trim the remaining content content = content[split_index:].strip()
chunks.append(chunk) await ctx.send(f"{prefix}{chunk}") # Send the chunk
# Send each chunk
for chunk in chunks:
await ctx.send(f"{prefix}{chunk}")
async def setup(bot): async def setup(bot):
"""✅ Correct async cog setup for Redbot""" """✅ Correct async cog setup for Redbot"""