#37 Implement v1 Web Apps #41

Merged
logan merged 58 commits from #37-implement-webapps into master 2023-08-04 23:46:50 -04:00
Showing only changes of commit e6332dffc9 - Show all commits

View File

@@ -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,9 +14,10 @@ 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) => {
@@ -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 = {