From a294b8c668e349d667749ef09bba57b3090310d4 Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Tue, 2 Jan 2024 20:55:16 -0500 Subject: [PATCH] Minor fixes and adding a forgotten component of ending a call --- breadbot.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/breadbot.js b/breadbot.js index e5478b5..c09752e 100644 --- a/breadbot.js +++ b/breadbot.js @@ -100,6 +100,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { console.log("\tJoining a call") var newCallID = await sqlutil.registerNewCall(newState.guild.id, newState.channelId, new Date()) + existingCallID = newCallID // To ensure all the stuff that happens after call creation works console.log(`\tNext call ID ${newCallID}`) @@ -149,7 +150,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { var markedUserInCall = await sqlutil.registerUserInCall(existingCallID, newState.member.id) if (!markedUserInCall) { - console.log(`Something went wrong when marking user in voice call: ${newState.member.id} - ${newState.member.channelId}`) + console.log(`Something went wrong when marking user in voice call: ${newState.member.id} - ${newState.channelId}`) } } else { console.log(`Something went wrong when registering user for call: ${newState.member.id} - ${newState.member.username}`) @@ -161,7 +162,7 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { console.log(`Channel Exit Detected ${oldState.guild.id} - ${oldState.channelId} - ${oldState.member.id}`) - var existingCallID = await sqlutil.inCall(oldState.guild.id, newState.channelId) + var existingCallID = await sqlutil.inCall(oldState.guild.id, oldState.channelId) console.log(`Existing call ID: ${existingCallID}`) @@ -173,6 +174,12 @@ client.on(Events.VoiceStateUpdate, async (oldState, newState) => { if (usersInCall == 0) { const connection = getVoiceConnection(oldState.guild.id) connection.disconnect() + + var didUpdateEndTime = await sqlutil.updateCallEndTime(existingCallID, new Date()) + + if (!didUpdateEndTime) { + console.log(`Failed to mark call id ${existingCallID} as ended with an end date`) + } } } else { console.log("Couldn't find a call ID based on the guild and channel info, was Breadbot in the call?")