complete restructure

This commit is contained in:
2026-08-19 13:16:43 -04:00
parent d7b6f28cbd
commit f87e1d51ef
60 changed files with 8176 additions and 5143 deletions
+41
View File
@@ -0,0 +1,41 @@
"""Text chunking utilities for sending long content within Discord's limit."""
from __future__ import annotations
def split_message(text: str, limit: int = 1900) -> list[str]:
"""Split ``text`` into chunks of at most ``limit`` characters.
Splits on newlines first so a line is never broken mid-text when
avoidable; a single line longer than ``limit`` is hard-split by plain
code-point slicing (Python ``str`` slicing is code-point safe, so no
lone surrogates are produced). Multi-codepoint grapheme clusters (e.g.
some emoji) are not protected — this matches the previous behavior and
keeps the dependency footprint at zero.
Guarantees ``"".join(split_message(text, limit)) == text``.
"""
if not text:
return []
if limit <= 0:
raise ValueError("limit must be a positive integer")
chunks: list[str] = []
current = ""
for raw_line in text.splitlines(keepends=True):
line = raw_line
while len(line) > limit:
if current:
chunks.append(current)
current = ""
chunks.append(line[:limit])
line = line[limit:]
if len(current) + len(line) <= limit:
current += line
else:
if current:
chunks.append(current)
current = line
if current:
chunks.append(current)
return chunks