updated sendMessageAsAttachment to returnBufferFromText and updated commands/webhookHelper accordingly

This commit is contained in:
Aster Fialla
2026-02-18 09:19:44 -05:00
parent 152bc8873d
commit 400e40a405
3 changed files with 17 additions and 8 deletions

View File

@@ -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.

View File

@@ -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<string, Buffer>} 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}
}
}

View File

@@ -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 {