From 7c9be47b6479b5ac07f73de2e766f79719a5e7ea Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 26 Mar 2023 00:44:33 -0400 Subject: [PATCH] Improve command logging and update function to async --- Client/discord-bot/controllers/audioController.js | 2 +- .../discord-bot/utilities/executeConsoleCommand.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Client/discord-bot/controllers/audioController.js b/Client/discord-bot/controllers/audioController.js index a8dd3b8..7065a20 100644 --- a/Client/discord-bot/controllers/audioController.js +++ b/Client/discord-bot/controllers/audioController.js @@ -2,7 +2,7 @@ import { getDeviceID } from '../utilities/configHandler.js'; // Modules import alsaInstance from 'alsa-capture'; -import { executeAsyncConsoleCommand } from "../utilities/executeConsoleCommand.js"; +import executeAsyncConsoleCommand from "../utilities/executeConsoleCommand.js"; // Debug import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js"; // Global Vars diff --git a/Client/discord-bot/utilities/executeConsoleCommand.js b/Client/discord-bot/utilities/executeConsoleCommand.js index 215036e..f2affca 100644 --- a/Client/discord-bot/utilities/executeConsoleCommand.js +++ b/Client/discord-bot/utilities/executeConsoleCommand.js @@ -1,13 +1,14 @@ // Modules import { promisify } from 'util'; +import { exec } from "child_process"; // Debug import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js"; // Global Vars const log = new ModuleDebugBuilder("bot", "executeConsoleCommand"); -const exec = promisify(require('child_process').exec); +const execCommand = promisify(exec); -export default function executeAsyncConsoleCommand(consoleCommand) { +export async function executeAsyncConsoleCommand(consoleCommand) { // Check to see if the command is a real command // TODO needs to be improved const acceptableCommands = [ "arecord -L" ]; @@ -15,8 +16,13 @@ export default function executeAsyncConsoleCommand(consoleCommand) { log.WARN("Console command is not acceptable: ", consoleCommand); return undefined; } - const tempOutput = exec(); + log.DEBUG("Running console command: ", consoleCommand); + + const tempOutput = await execCommand(consoleCommand); + const output = tempOutput.stdout.trim(); + + log.DEBUG("Executed Console Command Response: ", output) // TODO add some error checking - return tempOutput.stdout.trim(); + return output; } \ No newline at end of file