Updates to join (server/client)
- Check if the available nodes are connected to a vc in the given guild
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import { requestNodeJoinSystem } from '../../modules/socketServerWrappers.mjs';
|
||||
import { requestNodeJoinSystem, checkIfNodeIsConnectedToVC } from '../../modules/socketServerWrappers.mjs';
|
||||
import { getSystemsByNuid, getAllSystems, getSystemByName } from '../../modules/mongoSystemsWrappers.mjs';
|
||||
|
||||
// Exporting data property
|
||||
@@ -39,32 +39,35 @@ export async function execute(nodeIo, interaction) {
|
||||
const selectedSystem = interaction.options.getString('system');
|
||||
|
||||
try {
|
||||
// Get all open socket nodes
|
||||
const openSockets = await nodeIo.allSockets(); // TODO - Filter the returned nodes to only nodes that have the radio capability
|
||||
console.log("All open sockets: ", openSockets);
|
||||
|
||||
// Get the selected system object from the DB
|
||||
const system = await getSystemByName(selectedSystem);
|
||||
|
||||
// Function wrapper to request the selected/only node to join the selected system
|
||||
const joinSelectedNode = async (selectedNodeSocketId) => {
|
||||
const openSocket = await nodeIo.sockets.sockets.get(selectedNodeSocketId);
|
||||
console.log("Joining selected open socket:", openSocket.id, system.name, channelToJoin.id, openSocket.node.name);
|
||||
console.log("Joining selected open socket:", selectedNodeSocketId, system.name, channelToJoin.id, openSocket.node.name);
|
||||
|
||||
// Ask the node to join the selected channel and system
|
||||
await requestNodeJoinSystem(openSocket, system.name, channelToJoin.id);
|
||||
}
|
||||
|
||||
// Get all open socket nodes
|
||||
const openSockets = [...await nodeIo.allSockets()]; // TODO - Filter the returned nodes to only nodes that have the radio capability
|
||||
console.log("All open sockets: ", openSockets);
|
||||
|
||||
var availableNodes = [];
|
||||
// Check each open socket to see if the ID is included in the selected system
|
||||
await openSockets.forEach(openSocket => {
|
||||
openSocket = nodeIo.sockets.sockets.get(openSocket);
|
||||
// TODO - Determine if the node is already connected elsewhere
|
||||
// Check if this node has the requested system, if so add it to the availble array
|
||||
if (system.nodes.includes(openSocket.node.nuid)) {
|
||||
availableNodes.push(openSocket);
|
||||
// Check each open socket to see if the node has the requested system
|
||||
await Promise.all(openSockets.map(async openSocket => {
|
||||
openSocket = await nodeIo.sockets.sockets.get(openSocket);
|
||||
const connected = await checkIfNodeIsConnectedToVC(nodeIo, interaction.guild.id, openSocket.node.nuid);
|
||||
console.log("Connected:", connected);
|
||||
if (!connected) {
|
||||
// Check if this node has the requested system, if so add it to the availble array
|
||||
if (system.nodes.includes(openSocket.node.nuid)) {
|
||||
availableNodes.push(openSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
console.log("Availble nodes:", availableNodes, availableNodes.map(socket => socket.node.name));
|
||||
|
||||
@@ -77,7 +80,7 @@ export async function execute(nodeIo, interaction) {
|
||||
// Request the node to join
|
||||
await joinSelectedNode(availableNodes[0].id);
|
||||
// Let the user know
|
||||
await interaction.editReply({ content: `Ok ${interaction.member.id}, a bot will join your channel listening to *'${system.name}'* shortly`, components: [] });
|
||||
await interaction.editReply({ content: `Ok <@${interaction.member.id}>, a bot will join your channel listening to *'${system.name}'* shortly`, components: [] });
|
||||
} else if (availableNodes.length > 1) {
|
||||
// There is more than one node availble for the requested system
|
||||
const nodeSelectionButtons = []
|
||||
@@ -104,7 +107,7 @@ export async function execute(nodeIo, interaction) {
|
||||
// Run the local wrapper to listen to the selected node
|
||||
await joinSelectedNode(selectedNode.customId);
|
||||
// Let the user know
|
||||
await selectedNodeConfirmation.update({ content: `Ok ${interaction.member.id}, a bot will join your channel listening to *'${system.name}'*`, components: [] });
|
||||
await selectedNodeConfirmation.update({ content: `Ok <@${interaction.member.id}>, a bot will join your channel listening to *'${system.name}'*`, components: [] });
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
// Timeout the prompt if the user doesn't interact with it
|
||||
|
||||
Reference in New Issue
Block a user