From 92f4caad0cde1e88819bc694e3078c2dd083c402 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sat, 17 Jun 2023 19:25:47 -0400 Subject: [PATCH] Improve the join node verification system --- Server/commands/join.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Server/commands/join.js b/Server/commands/join.js index 6100498..20a34ed 100644 --- a/Server/commands/join.js +++ b/Server/commands/join.js @@ -3,7 +3,7 @@ const { SlashCommandBuilder } = require('discord.js'); const { DebugBuilder } = require("../utilities/debugBuilder"); const { getMembersInRole, getAllClientIds, filterAutocompleteValues } = require("../utilities/utils"); const { requestOptions, sendHttpRequest } = require("../utilities/httpRequests"); -const { getOnlineNodes, updateNodeInfo, addNodeConnection, getConnectionByNodeId } = require("../utilities/mysqlHandler"); +const { getOnlineNodes, updateNodeInfo, addNodeConnection, getConnectionByNodeId, getAllConnections } = require("../utilities/mysqlHandler"); // Global Vars const log = new DebugBuilder("server", "join"); @@ -13,10 +13,10 @@ const log = new DebugBuilder("server", "join"); * * @param {*} presetName The preset name to listen to on the client * @param {*} channelId The channel ID to join the bot to - * @param {*} clientIdsUsed EITHER A collection of clients that are currently connected OR a single discord client ID (NOT dev portal ID) that should be used to join the server with + * @param {*} connections EITHER A collection of clients that are currently connected OR a single discord client ID (NOT dev portal ID) that should be used to join the server with * @returns */ -async function joinServerWrapper(presetName, channelId, clientIdsUsed) { +async function joinServerWrapper(presetName, channelId, connections) { // Get nodes online var onlineNodes = await new Promise((recordResolve, recordReject) => { getOnlineNodes((nodeRows) => { @@ -45,16 +45,16 @@ async function joinServerWrapper(presetName, channelId, clientIdsUsed) { log.DEBUG("All clients: ", Object.keys(availableClientIds)); var selectedClientId; - if (typeof clientIdsUsed === 'string') { + if (typeof connections === 'string') { for (const availableClientId of availableClientIds) { - if (availableClientId.discordId != clientIdsUsed ) selectedClientId = availableClientId; + if (availableClientId.discordId != connections ) selectedClientId = availableClientId; } } else { - log.DEBUG("Client IDs Used: ", clientIdsUsed.keys()); - for (const usedClientId of clientIdsUsed.keys()) { - log.DEBUG("Used Client ID: ", usedClientId); - availableClientIds = availableClientIds.filter(cid => cid.discordId != usedClientId); + log.DEBUG("Open connections: ", connections); + for (const connection of connections) { + log.DEBUG("Used Client ID: ", connection); + availableClientIds = availableClientIds.filter(cid => cid.discordId != connection.clientObject.discordId); } log.DEBUG("Available Client IDs: ", availableClientIds); @@ -134,11 +134,11 @@ module.exports = { const channelId = interaction.member.voice.channel.id; log.DEBUG(`Join requested by: ${interaction.user.username}, to: '${presetName}', in channel: ${channelId} / ${guildId}`); - const onlineBots = await getMembersInRole(interaction); + const connections = await getAllConnections(); - log.DEBUG("Online Bots: ", onlineBots); + log.DEBUG("Current Connections: ", connections); - const selectedClientId = await joinServerWrapper(presetName, channelId, onlineBots.online); + const selectedClientId = await joinServerWrapper(presetName, channelId, connections); await interaction.editReply(`Ok, ${interaction.member}. **${selectedClientId.name}** is joining your channel.`); //await interaction.channel.send('**Pong.**'); // This will send a message to the channel of the interaction outside of the initial reply