xargana-srv/discord/classes/SystemCommandBase.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2025-04-17 16:11:04 +02:00
const CommandBase = require('./CommandBase');
const { exec } = require('child_process');
const util = require('util');
const execPromise = util.promisify(exec);
class SystemCommandBase extends CommandBase {
constructor(client) {
super(client);
// Add security check for all system commands
const originalExecute = this.execute;
this.execute = async function(interaction) {
if (interaction.user.id !== process.env.AUTHORIZED_USER_ID) {
return interaction.reply({
content: "You are not authorized to use system commands.",
ephemeral: true
});
}
return originalExecute.call(this, interaction);
};
}
async execCommand(command, options = {}) {
try {
const { stdout, stderr } = await execPromise(command, options);
return { success: true, stdout, stderr };
} catch (error) {
return {
success: false,
error: error.message,
stdout: error.stdout,
stderr: error.stderr
};
}
}
}
module.exports = SystemCommandBase;