From 6012351b3e9097ba12358d9e220f0a72d3c3471e Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Sun, 7 Jan 2024 15:30:15 -0500 Subject: [PATCH] Attempting to protect against call echo AND fix new call registry which wasn't working correctly it seems... --- breadbot.js | 48 ++++++++++++++++++++++++-------------------- utilities/sqlutil.js | 2 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/breadbot.js b/breadbot.js index 682216a..1ac7e34 100644 --- a/breadbot.js +++ b/breadbot.js @@ -135,29 +135,33 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { await entersState(connection, VoiceConnectionStatus.Ready, 20e3) const receiver = connection.receiver - receiver.speaking.on("start", (user_id) => { - receiver.subscribe(user_id, { - end: { - behavior: EndBehaviorType.AfterSilence, - duration: 500 - } + if (receiver.speaking.listenerCount("start") == 0) { + receiver.speaking.on("start", (user_id) => { + receiver.subscribe(user_id, { + end: { + behavior: EndBehaviorType.AfterSilence, + duration: 500 + } + }) + .pipe(new prism.opus.OggLogicalBitstream({ + opusHead: new prism.opus.OpusHead({ + channelCount: 2, + sampleRate: 48000 + }), + pageSizeControl: { + maxPackets: 10 + } + })) + .pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`)) + }) - .pipe(new prism.opus.OggLogicalBitstream({ - opusHead: new prism.opus.OpusHead({ - channelCount: 2, - sampleRate: 48000 - }), - pageSizeControl: { - maxPackets: 10 - } - })) - .pipe(fs.createWriteStream(media_voice_folder + path.sep + newCallID + path.sep + `${Date.now()}-${user_id}.ogg`)) - - }) - - receiver.speaking.on("end", (user_id) => { - logger.info(`User ${user_id} stopped speaking`) - }) + + receiver.speaking.on("end", (user_id) => { + logger.info(`User ${user_id} stopped speaking`) + }) + } else { + logger.info("Attempted to create a new start and end listener for users who are speaking for some reason, receiver armor if statement protected against this") + } } catch (error) { logger.error(error) } diff --git a/utilities/sqlutil.js b/utilities/sqlutil.js index a7a4f59..0d7d79f 100644 --- a/utilities/sqlutil.js +++ b/utilities/sqlutil.js @@ -176,7 +176,7 @@ async function inCall(server_snowflake, channel_snowflake) { async function registerNewCall(server_snowflake, channel_snowflake, call_start_time) { return connection_pool.query("INSERT INTO call_states (server_snowflake, channel_snowflake, call_start_time, call_end_time, call_consolidated, call_transcribed, call_data_cleaned_up) VALUES (?, ?, ?, NULL, 0, 0, 0)", [server_snowflake, channel_snowflake, call_start_time]).then(async ([rows, fields]) => { - if (rows.length == 0) { + if (typeof rows.insertId === 'undefined') { return -1; } else { return rows.insertId