Improve command logging and update function to async
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
import { getDeviceID } from '../utilities/configHandler.js';
|
import { getDeviceID } from '../utilities/configHandler.js';
|
||||||
// Modules
|
// Modules
|
||||||
import alsaInstance from 'alsa-capture';
|
import alsaInstance from 'alsa-capture';
|
||||||
import { executeAsyncConsoleCommand } from "../utilities/executeConsoleCommand.js";
|
import executeAsyncConsoleCommand from "../utilities/executeConsoleCommand.js";
|
||||||
// Debug
|
// Debug
|
||||||
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
||||||
// Global Vars
|
// Global Vars
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
// Modules
|
// Modules
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
|
import { exec } from "child_process";
|
||||||
// Debug
|
// Debug
|
||||||
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
|
||||||
// Global Vars
|
// Global Vars
|
||||||
const log = new ModuleDebugBuilder("bot", "executeConsoleCommand");
|
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
|
// Check to see if the command is a real command
|
||||||
// TODO needs to be improved
|
// TODO needs to be improved
|
||||||
const acceptableCommands = [ "arecord -L" ];
|
const acceptableCommands = [ "arecord -L" ];
|
||||||
@@ -15,8 +16,13 @@ export default function executeAsyncConsoleCommand(consoleCommand) {
|
|||||||
log.WARN("Console command is not acceptable: ", consoleCommand);
|
log.WARN("Console command is not acceptable: ", consoleCommand);
|
||||||
return undefined;
|
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
|
// TODO add some error checking
|
||||||
return tempOutput.stdout.trim();
|
return output;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user