81 lines
2.2 KiB
JavaScript
81 lines
2.2 KiB
JavaScript
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;
|
|
case 'list-deletions':
|
|
const deletions = await pool.query('SELECT * FROM discord_deletions');
|
|
if (!deletions.length) {
|
|
await interaction.reply({ content: 'No pending deletions.', ephemeral: true });
|
|
return;
|
|
}
|
|
|
|
const deletionList = deletions.map((deletion) => {
|
|
return `Member: <@${deletion.discordId}> (${deletion.discordId}), Extension: ${deletion.extension}, Delete At: <t:${deletion.deleteAt / 1000}>`;
|
|
});
|
|
|
|
await interaction.reply({ content: deletionList.join('\n'), ephemeral: true });
|
|
break;
|
|
}
|
|
} |