From b248e7f40eade0cdc345479b00c42fb1eeb327fa Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 30 Apr 2023 03:29:38 -0400 Subject: [PATCH] Update debugging - Uniform client name --- Client/commands/leave.js | 2 +- Client/commands/status.js | 2 +- Client/config/botConfig.json | 4 ++-- Client/config/clientConfig.js | 2 +- Client/controllers/commandController.js | 19 +++++++++++-------- Client/utilities/configHandler.js | 2 +- Client/utilities/debugBuilder.js | 7 ++++++- Client/utilities/executeConsoleCommands.js | 2 +- Client/utilities/messageHandler.js | 2 +- 9 files changed, 25 insertions(+), 17 deletions(-) diff --git a/Client/commands/leave.js b/Client/commands/leave.js index cf61454..cd69d34 100644 --- a/Client/commands/leave.js +++ b/Client/commands/leave.js @@ -1,6 +1,6 @@ // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); -const log = new DebugBuilder("client-bot", "leave"); +const log = new DebugBuilder("client", "leave"); // Modules const { SlashCommandBuilder } = require('discord.js'); const { leave } = require("../controllers/commandController") diff --git a/Client/commands/status.js b/Client/commands/status.js index f0046fd..b17abad 100644 --- a/Client/commands/status.js +++ b/Client/commands/status.js @@ -1,6 +1,6 @@ // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); -const log = new DebugBuilder("client-bot", "status"); +const log = new DebugBuilder("client", "status"); // Modules const { status } = require('../controllers/commandController'); // Utilities diff --git a/Client/config/botConfig.json b/Client/config/botConfig.json index 03cd2b6..effa2c8 100644 --- a/Client/config/botConfig.json +++ b/Client/config/botConfig.json @@ -1,6 +1,6 @@ { "ApplicationID": "943742040255115304", "GuildID": "367396189529833472", - "DeviceID": "5", - "DeviceName": "VoiceMeeter Aux Output (VB-Audi" + "DeviceID": "1", + "DeviceName": "VoiceMeeter VAIO3 Output (VB-Au" } \ No newline at end of file diff --git a/Client/config/clientConfig.js b/Client/config/clientConfig.js index c9977dc..a27cc52 100644 --- a/Client/config/clientConfig.js +++ b/Client/config/clientConfig.js @@ -4,7 +4,7 @@ exports.clientConfig = { "id": 13, "name": "boilin balls in the hall", "ip": "172.16.100.150", - "port": 3001, + "port": 3010, "location": "the house", "nearbySystems": ["Westchester Cty. Simulcast"], "online": true diff --git a/Client/controllers/commandController.js b/Client/controllers/commandController.js index e12dd50..89ab0a4 100644 --- a/Client/controllers/commandController.js +++ b/Client/controllers/commandController.js @@ -1,6 +1,6 @@ // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); -const log = new DebugBuilder("client-bot", "commandController"); +const log = new DebugBuilder("client", "commandController"); // Modules const { joinVoiceChannel, VoiceConnectionStatus, getVoiceConnection } = require("@discordjs/voice"); const { OpusEncoder } = require("@discordjs/opus"); @@ -31,7 +31,7 @@ exports.join = async function join({interaction= undefined, guildID= undefined, log.DEBUG("Channel ID: ", channelID) log.DEBUG("Guild ID: ", guildID) - const voiceConnection = joinVoiceChannel({ + const voiceConnection = await joinVoiceChannel({ channelId: channelID, guildId: guildID, adapterCreator: guildObj.voiceAdapterCreator, @@ -41,21 +41,24 @@ exports.join = async function join({interaction= undefined, guildID= undefined, const audioInstance = await createAudioInstance(); - audioInstance.on('audio', (buffer) => { - buffer = Buffer.from(buffer); - log.DEBUG("Audio buffer: ", buffer); + log.VERBOSE("Audio Instance: ", audioInstance); + + audioInstance.on('data', buffer => { + //buffer = Buffer.from(buffer); + log.VERBOSE("Audio buffer: ", buffer); const encodedBuffer = encoder.encode(buffer); - log.DEBUG("Encoded packet: ", encodedBuffer); // TODO Add a function here to check the volume of either buffer and only play audio to discord when there is audio to be played voiceConnection.playOpusPacket(encodedBuffer); }) // Exit the audio handler when the bot disconnects voiceConnection.on(VoiceConnectionStatus.Destroyed, () => { - audioInstance.close(); + audioInstance.quit(); }) - if (guildID && callback) callback(); + audioInstance.start(); + + if (guildID && callback) return callback(); else return; } diff --git a/Client/utilities/configHandler.js b/Client/utilities/configHandler.js index ba687c8..7ddfa23 100644 --- a/Client/utilities/configHandler.js +++ b/Client/utilities/configHandler.js @@ -1,6 +1,6 @@ // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); -const log = new DebugBuilder("client-bot", "configController"); +const log = new DebugBuilder("client", "configController"); // Modules const { readFileSync } = require('fs'); const path = require("path"); diff --git a/Client/utilities/debugBuilder.js b/Client/utilities/debugBuilder.js index 1c2a621..a4e7b19 100644 --- a/Client/utilities/debugBuilder.js +++ b/Client/utilities/debugBuilder.js @@ -12,6 +12,11 @@ exports.DebugBuilder = class DebugBuilder { this.INFO = debug(`${appName}:${fileName}:INFO`); this.DEBUG = debug(`${appName}:${fileName}:DEBUG`); this.WARN = debug(`${appName}:${fileName}:WARNING`); - this.ERROR = debug(`${appName}:${fileName}:ERROR`); + this.VERBOSE = debug(`${appName}:${fileName}:VERBOSE`); + this.ERROR = (...messageParts) => { + const error = debug(`${appName}:${fileName}:ERROR`); + error(messageParts); + if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0); + } } } \ No newline at end of file diff --git a/Client/utilities/executeConsoleCommands.js b/Client/utilities/executeConsoleCommands.js index a4a2e55..d601ff1 100644 --- a/Client/utilities/executeConsoleCommands.js +++ b/Client/utilities/executeConsoleCommands.js @@ -4,7 +4,7 @@ const { exec } = require("child_process"); // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); // Global Vars -const log = new DebugBuilder("client-bot", "executeConsoleCommands"); +const log = new DebugBuilder("client", "executeConsoleCommands"); const execCommand = promisify(exec); diff --git a/Client/utilities/messageHandler.js b/Client/utilities/messageHandler.js index db43c7f..0e9f8c7 100644 --- a/Client/utilities/messageHandler.js +++ b/Client/utilities/messageHandler.js @@ -1,6 +1,6 @@ // Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); -const log = new DebugBuilder("client-bot", "messageHandler"); +const log = new DebugBuilder("client", "messageHandler"); exports.replyToInteraction = async function replyToInteraction(interaction, message){ interaction.reply({ content: message, fetchReply: true })