Testing some dev commands

This commit is contained in:
Christopher Cookman 2024-03-24 03:50:49 -06:00
parent 62c3087783
commit 03d5d6f98f
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
2 changed files with 116 additions and 1 deletions

View file

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

View file

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