From 400e40a40588f366433a81336a716928ddb07a60 Mon Sep 17 00:00:00 2001 From: Aster Fialla Date: Wed, 18 Feb 2026 09:19:44 -0500 Subject: [PATCH] updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly --- src/commands.js | 4 +++- src/helpers/messageHelper.js | 14 ++++++++------ src/helpers/webhookHelper.js | 7 ++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/commands.js b/src/commands.js index 893e203..469314c 100644 --- a/src/commands.js +++ b/src/commands.js @@ -59,7 +59,9 @@ cmds.set('import', { let errorsText = `${error.message}.\nThese errors occurred:\n${error.errors.join('\n')}`; await message.reply(errorsText).catch(async () => { - await messageHelper.sendMessageAsAttachment(errorsText, message); + const returnedBuffer = await messageHelper.returnBufferFromText(errorsText); + await message.reply({content: returnedBuffer.text, files: [{ name: 'text.pdf', data: returnedBuffer.file }] + }) }); } // If just one error was returned. diff --git a/src/helpers/messageHelper.js b/src/helpers/messageHelper.js index 1c0777a..66296f5 100644 --- a/src/helpers/messageHelper.js +++ b/src/helpers/messageHelper.js @@ -44,7 +44,7 @@ msgh.parseCommandArgs = function(content, commandName) { * @returns {Object} The proxy message object. * @throws {Error} If a proxy message is sent with no message within it. */ -msgh.parseProxyTags = async function (authorId, content, attachmentUrl= null){ +msgh.parseProxyTags = async function (authorId, content, attachmentUrl = null){ const members = await memberHelper.getMembersByAuthor(authorId); // If an author has no members, no sense in searching for proxy if (members.length === 0) { @@ -72,17 +72,19 @@ msgh.parseProxyTags = async function (authorId, content, attachmentUrl= null){ } /** - * Sends a message as an attachment if it's too long. + * Returns a text message that's too long as its text plus a file with the remaining text. * * @async * @param {string} text - The text of the message. - * @param {Message} message - The message object. + * @returns {Object} The text and buffer object * */ -msgh.sendMessageAsAttachment = async function (text, message) { +msgh.returnBufferFromText = async function (text) { if (text.length > 2000) { - const data = Buffer.from(text, 'utf-8'); - await message.reply({content: enums.err.IMPORT_ERROR, files: [{name: 'import-logs.txt', data}]}); + const truncated = text.substring(0, 2000); + const restOfText = text.substring(2001); + const file = Buffer.from(restOfText, 'utf-8'); + return {text: truncated, file: file} } } diff --git a/src/helpers/webhookHelper.js b/src/helpers/webhookHelper.js index ca5055e..c74a3e3 100644 --- a/src/helpers/webhookHelper.js +++ b/src/helpers/webhookHelper.js @@ -42,7 +42,12 @@ wh.replaceMessage = async function(client, message, text, member) { const channel = client.channels.get(message.channelId); const webhook = await wh.getOrCreateWebhook(client, channel).catch((e) =>{throw e}); const username = member.displayname ?? member.name; - await webhook.send({content: text, username: username, avatar_url: member.propic}); + await webhook.send({content: text, username: username, avatar_url: member.propic}).catch(async(e) => { + const returnedBuffer = await messageHelper.returnBufferFromText(text); + await webhook.send({content: returnedBuffer.text, username: username, avatar_url: member.propic, files: [{ name: 'text.pdf', data: returnedBuffer.file }] + }) + console.error(e); + }); await message.delete(); } else {