Working on #9
- Can join and leave from voice channels - Will check to make sure that the bot is in a given system or no system before joining - Cleaned up the socket client with wrappers - Added a new module to handle subprocesses for the client - Beginning workings on OP25 handler - Added OP25 config object generator with config exporter
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
|
||||
import { requestNodeJoinSystem, checkIfNodeIsConnectedToVC } from '../../modules/socketServerWrappers.mjs';
|
||||
import { requestNodeJoinSystem, checkIfNodeIsConnectedToVC, checkIfNodeHasOpenDiscordClient, getNodeCurrentListeningSystem } from '../../modules/socketServerWrappers.mjs';
|
||||
import { getSystemsByNuid, getAllSystems, getSystemByName } from '../../modules/mongoSystemsWrappers.mjs';
|
||||
|
||||
// Exporting data property
|
||||
@@ -63,11 +63,22 @@ export async function execute(nodeIo, interaction) {
|
||||
// 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 node has the requested system
|
||||
await Promise.all(openSockets.map(async openSocket => {
|
||||
openSocket = await nodeIo.sockets.sockets.get(openSocket);
|
||||
// Check if the node has an existing open client (meaning the radio is already being listened to)
|
||||
const hasOpenClient = await checkIfNodeHasOpenDiscordClient(openSocket);
|
||||
if (hasOpenClient) {
|
||||
let currentSystem = await getNodeCurrentListeningSystem(openSocket);
|
||||
if (currentSystem != system.name) {
|
||||
console.log("Node is listening to a different system than requested", openSocket.node.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the bot has an open voice connection in the requested server already
|
||||
const connected = await checkIfNodeIsConnectedToVC(nodeIo, interaction.guild.id, openSocket.node.nuid);
|
||||
console.log("Connected:", connected);
|
||||
if (!connected) {
|
||||
@@ -76,6 +87,7 @@ export async function execute(nodeIo, interaction) {
|
||||
availableNodes.push(openSocket);
|
||||
}
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
console.log("Availble nodes:", availableNodes.map(socket => socket.node.name));
|
||||
|
||||
@@ -182,6 +182,51 @@ export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
|
||||
return socketsConnectedToVC;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the given node has an open discord client
|
||||
* @param {any} openSocket The open socket connection with the node to check
|
||||
* @returns {boolean} If the given node has an open discord client or not
|
||||
*/
|
||||
export const checkIfNodeHasOpenDiscordClient = async (openSocket) => {
|
||||
// Check the open socket to see if the node has an open discord client
|
||||
let hasOpenDiscordClient = false;
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-discord-open-client', (status) => {
|
||||
if (status) {
|
||||
console.log("Socket has an open discord client:", openSocket.node.name, status);
|
||||
hasOpenDiscordClient = true;
|
||||
} else {
|
||||
console.log("Socket does NOT have an open discord client:", openSocket.node.name);
|
||||
}
|
||||
res();
|
||||
})
|
||||
});
|
||||
|
||||
return hasOpenDiscordClient;
|
||||
}
|
||||
|
||||
export const getNodeCurrentListeningSystem = async (openSocket) => {
|
||||
const hasOpenClient = checkIfNodeHasOpenDiscordClient(openSocket);
|
||||
if (!hasOpenClient) return undefined;
|
||||
|
||||
// check what system the socket is listening to
|
||||
let currentSystem = undefined;
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-current-system', (system) => {
|
||||
if (system) {
|
||||
console.log("Socket is listening to system:", openSocket.node.name, system);
|
||||
currentSystem = system;
|
||||
} else {
|
||||
console.log("Socket is not currently listening to a system:", openSocket.node.name);
|
||||
}
|
||||
res();
|
||||
})
|
||||
});
|
||||
|
||||
return currentSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to check if the given NUID is connected to a VC
|
||||
* @param {any} nodeIo The nodeIo object that contains the IO server
|
||||
|
||||
Reference in New Issue
Block a user