diff --git a/commands.json b/commands.json index 55955f2..eb5a726 100644 --- a/commands.json +++ b/commands.json @@ -78,6 +78,68 @@ } ] }, + { + "name": "dev", + "description": "Developer only commands", + "type": 1, + "default_member_permissions": 0, + "options": [ + { + "name": "fwconsole", + "description": "Run an fwconsole command", + "type": 1, + "default_member_permissions": 0, + "options": [ + { + "name": "command", + "description": "The command to run", + "type": 3, + "required": true + } + ] + }, + { + "name": "asterisk", + "description": "Run an asterisk CLI command", + "type": 1, + "default_member_permissions": 0, + "options": [ + { + "name": "command", + "description": "The command to run", + "type": 3, + "required": true + } + ] + }, + { + "name": "shell", + "description": "Run a shell command", + "type": 1, + "default_member_permissions": 0, + "options": [ + { + "name": "command", + "description": "The command to run", + "type": 3, + "required": true + }, + { + "name": "timeout", + "description": "The timeout for the command if it doesn't return (in seconds). Default is none!", + "type": 4, + "required": false + } + ] + }, + { + "name": "restart", + "description": "Restart the bot", + "type": 1, + "default_member_permissions": 0 + } + ] + }, { "name": "Lookup Extension", "type": 2 diff --git a/index.js b/index.js index ea214b6..389896d 100644 --- a/index.js +++ b/index.js @@ -1070,7 +1070,7 @@ dcClient.on('interactionCreate', async interaction => { // switch subcommand switch (interaction.options.getSubcommand()) { case "silence": // SSH run `asterisk -x "channel request hangup all" - + sshConn.exec("asterisk -x 'channel request hangup all'", (err, stream) => { if (err) { interaction.reply({ @@ -1140,6 +1140,59 @@ dcClient.on('interactionCreate', async interaction => { }); } break; + case "dev": // Developer commands + // check if the user is a developer + if (!config.discord.developers.includes(interaction.user.id)) { + interaction.reply({ + content: "You're not a developer!", + ephemeral: true + }); + break; + } + + // switch subcommand + switch (interaction.options.getSubcommand()) { + case "fwconsole": // Run a fwconsole command + await interaction.deferReply({ + ephemeral: true + }); + let cmd = interaction.options.get("command").value; + sshConn.exec(`fwconsole ${cmd}`, (err, stream) => { + if (err) { + interaction.editReply(`Error running command: ${err}`); + sendLog(`${colors.red("[ERROR]")} ${err}`); + } + stream.on("data", (data) => { + console.log("DATA: " + data); + }) + stream.on('exit', (code, signal) => { + interaction.editReply(`Ran command \`${cmd}\``); + sendLog(`${colors.green("[INFO]")} Ran command ${cmd}`); + }); + }); + break; + case "restart": // Restart the bot + await interaction.reply({ + content: "Restarting the bot...", + ephemeral: true + }) + sendLog(`${colors.green("[INFO]")} Restarting the bot`); + dcClient.destroy().then(() => { + console.log("Disconnected from Discord"); + }); + conn.end().then(() => { + console.log("Disconnected from MySQL"); + }); + sshConn.end(); + console.log("Disconnected from SSH") + setTimeout(() => { + process.exit(); + }, 1000); + break; + case "asterisk": // Asterisk CLI command + break; // for now + } + break; default: break; }