Write content to file if string is too big to send

master
Caleb Fontenot 2023-04-05 08:30:58 +07:00
parent d369ac2d93
commit 1f70cb9b1c
2 changed files with 25 additions and 9 deletions

@ -1,7 +1,7 @@
const { SlashCommandBuilder } = require('discord.js');
var abbreviationKey = require("../abbreviation_key.json");
const fs = require('node:fs');
var path = require('node:path');;
var path = require('node:path');
//console.log(abbreviationKey);
module.exports = {

@ -1,4 +1,6 @@
const { SlashCommandBuilder, Discord, codeBlock } = require('discord.js');
const { SlashCommandBuilder, Discord, codeBlock, EmbedBuilder } = require('discord.js');
const fs = require('fs');
var path = require('node:path');
//const { writeFile } = require('../main.cjs');
module.exports = {
@ -37,19 +39,33 @@ module.exports = {
output = design4(inputString);
}
console.log(codeBlock("", output));
writeFile();
let testLength = "\n" + 'output length was ' + (output.length) + " characters.";
if (output.length + testLength.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.)");
return;
//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 replyString = "output length was " + (output.length) + " characters.";
let filePath = writeFile(output);
await interaction.reply({content:replyString, files: [filePath] });
fs.unlinkSync(filePath); // Delete file once we're done with it
} else {
await interaction.reply(codeBlock("", output) + testLength);
}
await interaction.reply(codeBlock("", output) + testLength);
console.log("User " + interaction.user.tag + " ran /drawtriangle");
},
};
function writeFile() {
console.log("Write file was called")
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;
}
function design1(input) {
@ -153,7 +169,7 @@ function design4(input) {
}
// for horizontal movement
for (let i = 0; i <= 2 * radius; i++) {
if (i != mid && j != 0) {
if (i != mid) {
// for vertical movement
for (let j = 0; j <= 2 * radius; j++) {