Add dpaste for overflow

This commit is contained in:
dlinux-host 2024-10-02 18:50:33 -04:00
parent 35e4c48991
commit 440fd75f13
2 changed files with 121 additions and 82 deletions

View File

@ -10,6 +10,7 @@
"license": "ISC",
"description": "",
"dependencies": {
"cmd-promise": "^1.2.0",
"discord.js": "^14.16.3",
"jsonfile": "^6.1.0",
"mysql2": "^3.11.3",

View File

@ -4,7 +4,8 @@ import unirest from 'unirest';
import { readFileSync } from 'fs';
import mysql from 'mysql2';
const userWorkingDirectories = new Map();
import fs from 'fs';
import cmd from 'cmd-promise';
let sshSurfID; // Variable to store the user ID from the database
// Paths to config and tokens files
@ -380,7 +381,42 @@ case 'x': {
pwd: userPWD // Use the current directory or default to '/'
});
// Format the command output in a markdown code block
// Handle the command output
if (execResponse.stdout.length > 2020) {
// If the output is too large, save it to a temporary file and upload to a paste service
const tempFilePath = '/tmp/paste';
const pasteCommand = `Command: ${command} | Container Owner: ${interaction.user.username}\n${execResponse.stdout}`;
fs.writeFileSync(tempFilePath, pasteCommand, (err) => {
if (err) {
console.error(err);
return;
}
});
const pasteout = await cmd("sleep 2; cat /tmp/paste | dpaste");
// Create an embed with the paste link
const mainEmbed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(`Container Owner: ${interaction.user.username}`)
.setDescription(`The command: ${command} was too large for Discord.`)
.addFields(
{
name: 'Please check the below output log:',
value: pasteout.stdout.replace("Pro tip: you can password protect your paste just by typing a username and password after your paste command.", "")
.replace("Paste Saved: ", "")
.replace("-------------------------------------------------------", "")
}
)
.setFooter({ text: `Requested by ${interaction.user.username}`, iconURL: `${interaction.user.displayAvatarURL()}` });
await interaction.editReply({ embeds: [mainEmbed] });
} else {
// If the output is small enough, format it in a markdown code block
let replyMessage = `\`\`\`\n${execResponse.stdout || 'No output'}\n\`\`\``;
// If there is an error, append the error message in another markdown code block
@ -390,6 +426,7 @@ case 'x': {
// Reply with the formatted message
await interaction.editReply(replyMessage);
}
break;
}
@ -401,6 +438,7 @@ function RemoveLastDirectoryPartOf(the_url, num) {
}
case 'notify':
const message = interaction.options.getString('message');
const notifyResponse = await makeApiRequest('/notify', apiToken, interaction, 'post', {