Add admin commands

This commit is contained in:
Christopher Cookman 2025-01-25 09:06:26 -07:00
parent 1451549928
commit 5480402a8c
2 changed files with 48 additions and 0 deletions

View file

@ -78,6 +78,7 @@ client.on('ready', async () => {
}); });
client.on('interactionCreate', async interaction => { 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) { switch(interaction.type) {
case Discord.InteractionType.ApplicationCommand: case Discord.InteractionType.ApplicationCommand:
const command = require(`./interactionHandlers/commands/${interaction.commandName}`); const command = require(`./interactionHandlers/commands/${interaction.commandName}`);

View file

@ -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;
}
}