NoMoreAcronyms/commands/listPhrases.cjs

40 lines
1.7 KiB
JavaScript

2023-04-04 17:20:28 +07:00
const { codeBlock } = require("discord.js");
2024-08-06 11:10:50 +07:00
const fs = require('fs');
var path = require('node:path');
2023-04-01 11:29:41 +07:00
const { SlashCommandBuilder, Discord } = require('discord.js');
var abbreviationKey = require("../abbreviation_key.json");
module.exports = {
data: new SlashCommandBuilder()
.setName('list_phrases')
.setDescription('Lists phrases in target phrases.'),
2023-04-04 17:20:28 +07:00
async execute(interaction, client) {
2023-11-01 20:35:13 +07:00
let replyDesc = "Here are the current phrases in the phrase list:";
2024-08-06 11:10:50 +07:00
let replyString = JSON.stringify(abbreviationKey.target_phrases, null, " ");
2023-11-01 20:35:13 +07:00
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);
2024-08-06 11:10:50 +07:00
await interaction.reply({ content: replyDesc, files: [filePath] });
2023-11-01 20:35:13 +07:00
fs.unlinkSync(filePath); // Delete file once we're done with it
} else {
await interaction.reply(replyDesc + replyString);
2024-08-06 11:10:50 +07:00
}
2023-04-04 17:20:28 +07:00
console.log("User " + interaction.user.tag + " ran /list_phrases");
2023-04-01 11:29:41 +07:00
},
};
2023-11-01 20:35:13 +07:00
function writeFile(content) {
//console.log(content);
console.log("Attempting to write string to file...");
2024-08-06 11:10:50 +07:00
let filename = Date.now() + '.json';
2023-11-01 20:35:13 +07:00
console.log(filename);
var filePath = path.join(__dirname, '..', filename);
console.log(filePath);
fs.writeFile(filePath, content, err => {
if (err) {
console.error(err);
}
});
return filePath;
}