const { exec } = require('child_process'); const Discord = require('discord.js'); 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` await interaction.reply({ content: "Rebooting...", ephemeral: true }); await client.destroy(); log.info('Client destroyed.'); pool.end((err) => { if (err) { log.error('Error closing database pool:', err); } else { log.info('Database pool closed.'); } }); runCommand('reboot 0'); break; } }