forked from PluralFlux/PluralFlux
added handler to send string as an attachment if it's too long
This commit is contained in:
@@ -13,7 +13,8 @@
|
||||
"@fluxerjs/core": "^1.0.9",
|
||||
"pg": "^8.18.0",
|
||||
"pg-hstore": "^2.3.4",
|
||||
"sequelize": "^6.37.7"
|
||||
"sequelize": "^6.37.7",
|
||||
"tmp": "^0.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^30.2.0"
|
||||
|
||||
@@ -51,7 +51,10 @@ cmds.set('import', {
|
||||
if (error instanceof AggregateError) {
|
||||
// errors.message can be a list of successfully added members, or say that none were successful.
|
||||
let errorsText = `${error.message}.\nThese errors occurred:\n${error.errors.join('\n')}`;
|
||||
await message.reply(errorsText);
|
||||
|
||||
await message.reply(errorsText).catch(async () => {
|
||||
await messageHelper.sendMessageAsAttachment(errorsText, message);
|
||||
});
|
||||
}
|
||||
// If just one error was returned.
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {memberHelper} from "./memberHelper.js";
|
||||
import {enums} from "../enums.js";
|
||||
import tmp from "tmp";
|
||||
|
||||
const msgh = {};
|
||||
|
||||
@@ -55,10 +56,18 @@ msgh.parseProxyTags = async function (authorId, attachment, content){
|
||||
const removeSuffix = new RegExp(splitProxy[1] + "$");
|
||||
proxyMessage.message = content.replace(removePrefix, "").replace(removeSuffix, "");
|
||||
if (proxyMessage.message.length <= splitProxy[0].length + splitProxy[1].length && !attachment) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
||||
|
||||
}
|
||||
})
|
||||
return proxyMessage;
|
||||
}
|
||||
|
||||
msgh.sendMessageAsAttachment = async function(text, message) {
|
||||
if (text.length > 2000) {
|
||||
tmp.file(async (err, path, fd, cleanupCallback) => {
|
||||
if (err) throw err;
|
||||
await message.reply({attachments: [path]});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const messageHelper = msgh;
|
||||
|
||||
Reference in New Issue
Block a user