Fix postSystemMessage() text not being chunked

This would cause errors if the system message was over
2000 characters in length.
cshd
Dragory 2020-11-02 17:25:56 +02:00
parent d8e6222bae
commit 1210b2acaa
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 5 additions and 4 deletions

View File

@ -89,10 +89,11 @@ class Thread {
try { try {
let firstMessage; let firstMessage;
if (typeof content === "string") { const textContent = typeof content === "string" ? content : content.content;
// Content is a string, chunk it and send it as individual messages. if (textContent) {
// Text content is included, chunk it and send it as individual messages.
// Files (attachments) are only sent with the last message. // Files (attachments) are only sent with the last message.
const chunks = utils.chunkMessageLines(content); const chunks = utils.chunkMessageLines(textContent);
for (const [i, chunk] of chunks.entries()) { for (const [i, chunk] of chunks.entries()) {
// Only send embeds, files, etc. with the last message // Only send embeds, files, etc. with the last message
const msg = (i === chunks.length - 1) const msg = (i === chunks.length - 1)
@ -102,7 +103,7 @@ class Thread {
firstMessage = firstMessage || msg; firstMessage = firstMessage || msg;
} }
} else { } else {
// Content is a full message content object, send it as-is with the files (if any) // No text content, send as one message
firstMessage = await bot.createMessage(this.channel_id, content, file); firstMessage = await bot.createMessage(this.channel_id, content, file);
} }