From 5480402a8c223b6dd9a90c903b3c9acd6d1d403d Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sat, 25 Jan 2025 09:06:26 -0700 Subject: [PATCH] Add admin commands --- index.js | 1 + interactionHandlers/commands/admin.js | 47 +++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 interactionHandlers/commands/admin.js diff --git a/index.js b/index.js index 3f0a479..fa44337 100644 --- a/index.js +++ b/index.js @@ -78,6 +78,7 @@ client.on('ready', async () => { }); client.on('interactionCreate', async interaction => { + if (!interaction.inGuild()) return interaction.reply({ content: "This bot is not designed to be used in DMs.", ephemeral: true }); switch(interaction.type) { case Discord.InteractionType.ApplicationCommand: const command = require(`./interactionHandlers/commands/${interaction.commandName}`); diff --git a/interactionHandlers/commands/admin.js b/interactionHandlers/commands/admin.js new file mode 100644 index 0000000..fd251ca --- /dev/null +++ b/interactionHandlers/commands/admin.js @@ -0,0 +1,47 @@ +const { exec } = require('child_process'); + +const pool = global.pool +const fpbx = global.fpbx +const client = global.client +const log = global.log + + +const exec = (command) => { + return new Promise((resolve, reject) => { + require('child_process').exec(command, (error, stdout, stderr) => { + if (error) { + reject(`error: ${error.message}`); + return; + } + if (stderr) { + reject(`stderr: ${stderr}`); + return; + } + resolve(stdout); + }); + }); +} + +module.exports = {}; + +module.exports.execute = async (interaction) => { + const subcommand = interaction.options.getSubcommand(); + + switch (subcommand) { + case 'silence': // Run `asterisk -x "channel request hangup all" + exec('asterisk -x "channel request hangup all"').then((res) => { + interaction.reply({ content: ``, ephemeral: true }); + }); + break; + case 'reload': // Run `fwconsole reload` + exec('fwconsole reload').then((res) => { + interaction.reply({ content: res, ephemeral: true }); + }); + break; + case 'reboot': // Run `reboot 0` + exec('reboot 0').then((res) => { + interaction.reply({ content: "Rebooting...", ephemeral: true }); + }); + break; + } +} \ No newline at end of file