This commit is contained in:
2026-01-29 12:26:13 +01:00
parent ba0f116bc2
commit 6dbcadcaee
79 changed files with 2795 additions and 657 deletions

50
src/utils/discord.ts Normal file
View File

@@ -0,0 +1,50 @@
/**
* Discord message utilities
*/
/**
* Split a message into chunks that fit within Discord's limit
*/
export function splitMessage(content: string, maxLength = 1900): string[] {
if (content.length <= maxLength) {
return [content];
}
const chunks: string[] = [];
let remaining = content;
while (remaining.length > 0) {
if (remaining.length <= maxLength) {
chunks.push(remaining);
break;
}
// Try to split at a natural break point
let splitPoint = remaining.lastIndexOf("\n", maxLength);
if (splitPoint === -1 || splitPoint < maxLength / 2) {
splitPoint = remaining.lastIndexOf(" ", maxLength);
}
if (splitPoint === -1 || splitPoint < maxLength / 2) {
splitPoint = maxLength;
}
chunks.push(remaining.slice(0, splitPoint));
remaining = remaining.slice(splitPoint).trimStart();
}
return chunks;
}
/**
* Escape Discord markdown
*/
export function escapeMarkdown(text: string): string {
return text.replace(/([*_`~|\\])/g, "\\$1");
}
/**
* Format code block
*/
export function codeBlock(content: string, language = ""): string {
return `\`\`\`${language}\n${content}\n\`\`\``;
}