This commit is contained in:
2024-08-06 11:10:50 -05:00
parent 836f3de31d
commit bbc45e29e2
9 changed files with 1641 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
const { codeBlock } = require("discord.js");
const fs = require('fs');
var path = require('node:path');
const { SlashCommandBuilder, Discord } = require('discord.js');
var abbreviationKey = require("../abbreviation_key.json");
@@ -9,18 +10,15 @@ module.exports = {
.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, " ");
let replyString = 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] });
await interaction.reply({ content: replyDesc, 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");
},
};
@@ -28,7 +26,7 @@ module.exports = {
function writeFile(content) {
//console.log(content);
console.log("Attempting to write string to file...");
let filename = Date.now() + '.txt';
let filename = Date.now() + '.json';
console.log(filename);
var filePath = path.join(__dirname, '..', filename);
console.log(filePath);