diff --git a/backend/src/plugins/Cases/functions/getCaseEmbed.ts b/backend/src/plugins/Cases/functions/getCaseEmbed.ts index 6b5376b7..914960f9 100644 --- a/backend/src/plugins/Cases/functions/getCaseEmbed.ts +++ b/backend/src/plugins/Cases/functions/getCaseEmbed.ts @@ -2,10 +2,11 @@ import { Case } from "../../../data/entities/Case"; import { MessageContent } from "eris"; import moment from "moment-timezone"; import { CaseTypes } from "../../../data/CaseTypes"; -import { PluginData } from "knub"; +import { PluginData, helpers } from "knub"; import { CasesPluginType } from "../types"; import { CaseTypeColors } from "../../../data/CaseTypeColors"; import { resolveCaseId } from "./resolveCaseId"; +import { chunkLines, chunkMessageLines, emptyEmbedValue } from "../../../utils"; export async function getCaseEmbed( pluginData: PluginData, @@ -51,10 +52,21 @@ export async function getCaseEmbed( if (theCase.notes.length) { theCase.notes.forEach((note: any) => { const noteDate = moment(note.created_at); - embed.fields.push({ - name: `${note.mod_name} at ${noteDate.format("YYYY-MM-DD [at] HH:mm")}:`, - value: note.body, - }); + const chunks = chunkMessageLines(note.body, 1014); + + for (let i = 0; i < chunks.length; i++) { + if (i === 0) { + embed.fields.push({ + name: `${note.mod_name} at ${noteDate.format("YYYY-MM-DD [at] HH:mm")}:`, + value: chunks[i], + }); + } else { + embed.fields.push({ + name: emptyEmbedValue, + value: chunks[i], + }); + } + } }); } else { embed.fields.push({ diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 831129f4..967c3a3d 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -633,9 +633,12 @@ export function chunkLines(str: string, maxChunkLength = 2000): string[] { /** * Chunks a long message to multiple smaller messages, retaining leading and trailing line breaks, open code blocks, etc. + * + * Default maxChunkLength is 1990, a bit under the message length limit of 2000, so we have space to add code block + * shenanigans to the start/end when needed. Take this into account when choosing a custom maxChunkLength as well. */ -export function chunkMessageLines(str: string): string[] { - const chunks = chunkLines(str, 1990); // We don't split at exactly 2000 to be able to do the stuff below +export function chunkMessageLines(str: string, maxChunkLength = 1990): string[] { + const chunks = chunkLines(str, maxChunkLength); let openCodeBlock = false; return chunks.map(chunk => {