Initial update to try and fix #1
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
// Debug
|
||||
import ModuleDebugBuilder from "./moduleDebugBuilder.js";
|
||||
const log = new ModuleDebugBuilder("bot", "configHandler");
|
||||
// Modules
|
||||
import { readFileSync } from 'fs';
|
||||
import path from "path";
|
||||
|
||||
export function getConfig() {
|
||||
return JSON.parse(readFileSync(path.resolve("discord-bot/config/botConfig.json")));
|
||||
}
|
||||
|
||||
export function getTOKEN() {
|
||||
const parsedJSON = getConfig();
|
||||
const token = parsedJSON.TOKEN;
|
||||
|
||||
log.DEBUG("Discord API Token: ", token)
|
||||
return token;
|
||||
}
|
||||
|
||||
export function getGuildID() {
|
||||
const parsedJSON = getConfig();
|
||||
const guildID = parsedJSON.GuildID;
|
||||
|
||||
log.DEBUG("Guild ID: ", guildID);
|
||||
return guildID;
|
||||
}
|
||||
|
||||
export function getApplicationID() {
|
||||
const parsedJSON = getConfig();
|
||||
const appID = parsedJSON.ApplicationID;
|
||||
|
||||
log.DEBUG("Application ID: ", appID);
|
||||
return appID;
|
||||
}
|
||||
|
||||
export function getDeviceID(){
|
||||
const parsedJSON = getConfig();
|
||||
const deviceID = parseInt(parsedJSON.DeviceID);
|
||||
|
||||
log.DEBUG("Device ID: ", deviceID);
|
||||
return deviceID;
|
||||
}
|
||||
|
||||
export function getDeviceName(){
|
||||
const parsedJSON = getConfig();
|
||||
const deviceName = parsedJSON.DeviceName;
|
||||
|
||||
log.DEBUG("Device Name: ", deviceName);
|
||||
return deviceName;
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
// 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 execCommand = promisify(exec);
|
||||
|
||||
|
||||
export default async 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;
|
||||
}
|
||||
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 output;
|
||||
}
|
||||
|
||||
export async function returnAlsaDeviceObject() {
|
||||
const listAlsaDevicesCommand = "arecord -L";
|
||||
const commandResponse = await executeAsyncConsoleCommand(listAlsaDevicesCommand);
|
||||
const brokenCommand = String(commandResponse).split('\n');
|
||||
var devices = [];
|
||||
var i = 0;
|
||||
|
||||
for (const responseLine of brokenCommand) {
|
||||
if (String(responseLine) && !String(responseLine).match(/^\s/g)) {
|
||||
const tempDevice = {
|
||||
id: i,
|
||||
name: responseLine
|
||||
}
|
||||
devices.push(tempDevice);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// Debug
|
||||
import ModuleDebugBuilder from "./moduleDebugBuilder.js";
|
||||
const log = new ModuleDebugBuilder("bot", "messageHandler");
|
||||
|
||||
export function replyToInteraction(interaction, message){
|
||||
interaction.reply({ content: message, fetchReply: true })
|
||||
.then((message) => log.DEBUG(`Reply sent with content ${message.content}`))
|
||||
.catch((err) => log.ERROR(err));
|
||||
}
|
||||
Reference in New Issue
Block a user