49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
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
|
|
});
|
|
}
|
|
|
|
// Additional DM-only check
|
|
if (interaction.channel.type !== 'DM') {
|
|
return interaction.reply({
|
|
content: "System commands can only be used in Direct Messages for security.",
|
|
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;
|