comphensate for long JSON output

master
Caleb Fontenot 2023-11-01 20:35:13 +07:00
parent 8a05ffd931
commit 7ec0366062
1 changed files with 27 additions and 0 deletions

@ -8,7 +8,34 @@ module.exports = {
.setName('list_phrases')
.setDescription('Lists phrases in target phrases.'),
async execute(interaction, client) {
let replyDesc = "Here are the current phrases in the phrase list:";
let replyString = codeBlock("json", JSON.stringify(abbreviationKey.target_phrases, null, " ");
if (replyString.length + replyDesc.length > 2000) {
//await interaction.reply('Error: String is too big. Resultant output would be too big to send to Discord. (the output length was ' + (output.length + testLength.length) + " characters.)");
let filePath = writeFile(replyString);
await interaction.reply({ content: replyString, files: [filePath] });
fs.unlinkSync(filePath); // Delete file once we're done with it
} else {
await interaction.reply(replyDesc + replyString);
}
await interaction.reply("Here are the current phrases in the phrase list:" + codeBlock("json", JSON.stringify(abbreviationKey.target_phrases, null, " ")));
console.log("User " + interaction.user.tag + " ran /list_phrases");
},
};
function writeFile(content) {
//console.log(content);
console.log("Attempting to write string to file...");
let filename = Date.now() + '.txt';
console.log(filename);
var filePath = path.join(__dirname, '..', filename);
console.log(filePath);
fs.writeFile(filePath, content, err => {
if (err) {
console.error(err);
}
});
return filePath;
}