From 4967b412c464b5c9421ac943adb1a6a342851c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Sat, 11 May 2019 20:28:26 +0200 Subject: [PATCH] Send a command to the server --- commands/owner/exec.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 commands/owner/exec.js diff --git a/commands/owner/exec.js b/commands/owner/exec.js new file mode 100644 index 00000000..91cb2753 --- /dev/null +++ b/commands/owner/exec.js @@ -0,0 +1,38 @@ +const { Command } = require('discord-akairo'); +const util = require('util'); +const exec = util.promisify(require('child_process').exec); + +class execCommand extends Command { + constructor() { + super('exec', { + aliases: ['exec'], + category: 'owner', + ownerOnly: 'true', + args: [ + { + id: 'exec', + type: 'string', + match: 'rest' + } + ], + description: { + content: 'execute a command on the server', + usage: '[a command on the server]', + examples: ['pm2 list'] + } + }); + } + + async exec(message, args) { + async function update() { + const { stdout, stderr } = await exec(args.exec).catch(err => { + return message.channel.send(`Oh no, an error has occured\n${err}`); + }); + message.channel.send(`stdout: ${stdout}`, { split: true }); + message.channel.send(`stderr: ${stderr}`, { split: true }); + } + return update(); + } +} + +module.exports = execCommand; \ No newline at end of file