Update join command to accept a specific node ID
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// Modules
|
// Modules
|
||||||
const { SlashCommandBuilder } = require('discord.js');
|
const { SlashCommandBuilder } = require('discord.js');
|
||||||
const { DebugBuilder } = require("../utilities/debugBuilder");
|
const { DebugBuilder } = require("../utilities/debugBuilder");
|
||||||
const { getMembersInRole, getAllClientIds, filterAutocompleteValues } = require("../utilities/utils");
|
const { getMembersInRole, getAllClientIds, filterAutocompleteValues, getKeyByArrayValue } = require("../utilities/utils");
|
||||||
const { requestOptions, sendHttpRequest } = require("../utilities/httpRequests");
|
const { requestOptions, sendHttpRequest } = require("../utilities/httpRequests");
|
||||||
const { getOnlineNodes, updateNodeInfo, addNodeConnection, getConnectionByNodeId, getAllConnections } = require("../utilities/mysqlHandler");
|
const { getOnlineNodes, updateNodeInfo, addNodeConnection, getConnectionByNodeId, getAllConnections } = require("../utilities/mysqlHandler");
|
||||||
|
|
||||||
@@ -14,15 +14,16 @@ const log = new DebugBuilder("server", "join");
|
|||||||
* @param {*} presetName The preset name to listen to on the client
|
* @param {*} presetName The preset name to listen to on the client
|
||||||
* @param {*} channelId The channel ID to join the bot to
|
* @param {*} channelId The channel ID to join the bot to
|
||||||
* @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
|
* @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
|
||||||
|
* @param {number} nodeId [OPTIONAL] The node ID to join with (will join with another node if given node is not available)
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async function joinServerWrapper(presetName, channelId, connections) {
|
async function joinServerWrapper(presetName, channelId, connections, nodeId = 0) {
|
||||||
// Get nodes online
|
// Get nodes online
|
||||||
var onlineNodes = await new Promise((recordResolve, recordReject) => {
|
var onlineNodes = await new Promise((recordResolve, recordReject) => {
|
||||||
getOnlineNodes((nodeRows) => {
|
getOnlineNodes((nodeRows) => {
|
||||||
recordResolve(nodeRows);
|
recordResolve(nodeRows);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check which nodes have the selected preset
|
// Check which nodes have the selected preset
|
||||||
onlineNodes = onlineNodes.filter(node => node.presets.includes(presetName));
|
onlineNodes = onlineNodes.filter(node => node.presets.includes(presetName));
|
||||||
@@ -63,7 +64,10 @@ async function joinServerWrapper(presetName, channelId, connections) {
|
|||||||
selectedClientId = availableClientIds[0];
|
selectedClientId = availableClientIds[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedNode = nodesCurrentlyAvailable[0];
|
let selectedNode;
|
||||||
|
if (nodeId > 0) selectedNode = getKeyByArrayValue(nodesCurrentlyAvailable, nodeId);
|
||||||
|
|
||||||
|
if (!selectedNode) selectedNode = nodesCurrentlyAvailable[0];
|
||||||
|
|
||||||
const reqOptions = new requestOptions("/bot/join", "POST", selectedNode.ip, selectedNode.port);
|
const reqOptions = new requestOptions("/bot/join", "POST", selectedNode.ip, selectedNode.port);
|
||||||
const postObject = {
|
const postObject = {
|
||||||
|
|||||||
Reference in New Issue
Block a user