const { exec } = require('child_process'); const pool = global.pool const fpbx = global.fpbx const client = global.client const log = global.log const runCommand = (command, onData) => { return new Promise((resolve, reject) => { const process = exec(command); process.stdout.on('data', (data) => { if (onData) { onData(data); } }); process.stderr.on('data', (data) => { reject(`stderr: ${data}`); }); process.on('close', (code) => { if (code !== 0) { reject(`process exited with code ${code}`); return; } resolve('Command executed successfully'); }); process.on('error', (error) => { reject(`error: ${error.message}`); }); }); } module.exports = {}; module.exports.execute = async (interaction) => { const subcommand = interaction.options.getSubcommand(); switch (subcommand) { case 'silence': // Run `asterisk -x "channel request hangup all" runCommand('asterisk -x "channel request hangup all"').then((res) => { interaction.reply({ content: `Silenced`, ephemeral: true }); }); break; case 'reload': // Run `fwconsole reload` await interaction.deferReply({ ephemeral: true }); runCommand('fwconsole reload', (data) => { interaction.editReply({ content: data, ephemeral: true }); }); break; case 'reboot': // Run `reboot 0` runCommand('reboot 0').then((res) => { interaction.reply({ content: "Rebooting...", ephemeral: true }); }); break; } }