Write content to file if string is too big to send
This commit is contained in:
parent
d369ac2d93
commit
1f70cb9b1c
@ -1,7 +1,7 @@
|
|||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
var abbreviationKey = require("../abbreviation_key.json");
|
var abbreviationKey = require("../abbreviation_key.json");
|
||||||
const fs = require('node:fs');
|
const fs = require('node:fs');
|
||||||
var path = require('node:path');;
|
var path = require('node:path');
|
||||||
//console.log(abbreviationKey);
|
//console.log(abbreviationKey);
|
||||||
|
|
||||||
module.exports = {
|
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');
|
//const { writeFile } = require('../main.cjs');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
@ -37,19 +39,33 @@ module.exports = {
|
|||||||
output = design4(inputString);
|
output = design4(inputString);
|
||||||
}
|
}
|
||||||
console.log(codeBlock("", output));
|
console.log(codeBlock("", output));
|
||||||
writeFile();
|
|
||||||
let testLength = "\n" + 'output length was ' + (output.length) + " characters.";
|
let testLength = "\n" + 'output length was ' + (output.length) + " characters.";
|
||||||
if (output.length + testLength.length > 2000) {
|
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.)");
|
//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;
|
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");
|
console.log("User " + interaction.user.tag + " ran /drawtriangle");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function writeFile() {
|
function writeFile(content) {
|
||||||
console.log("Write file was called")
|
//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) {
|
function design1(input) {
|
||||||
@ -153,7 +169,7 @@ function design4(input) {
|
|||||||
}
|
}
|
||||||
// for horizontal movement
|
// for horizontal movement
|
||||||
for (let i = 0; i <= 2 * radius; i++) {
|
for (let i = 0; i <= 2 * radius; i++) {
|
||||||
if (i != mid && j != 0) {
|
if (i != mid) {
|
||||||
// for vertical movement
|
// for vertical movement
|
||||||
for (let j = 0; j <= 2 * radius; j++) {
|
for (let j = 0; j <= 2 * radius; j++) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user