Files
DRB-CnC/Client/discord-bot/utilities/executeConsoleCommand.js
2023-03-26 00:36:19 -04:00

22 lines
763 B
JavaScript

// Modules
import { promisify } from 'util';
// Debug
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
// Global Vars
const log = new ModuleDebugBuilder("bot", "executeConsoleCommand");
const exec = promisify(require('child_process').exec);
export default function executeAsyncConsoleCommand(consoleCommand) {
// Check to see if the command is a real command
// TODO needs to be improved
const acceptableCommands = [ "arecord -L" ];
if (!acceptableCommands.includes(consoleCommand)) {
log.WARN("Console command is not acceptable: ", consoleCommand);
return undefined;
}
const tempOutput = exec();
// TODO add some error checking
return tempOutput.stdout.trim();
}