Added JSDoc to Join wrapper and updated wrapper to also take just a client ID string
This commit is contained in:
@@ -11,7 +11,12 @@ const path = require('path');
|
|||||||
const log = new DebugBuilder("server", "join");
|
const log = new DebugBuilder("server", "join");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This wrapper will check if there is an available node with the requested preset and if so checks for an available client ID to join with
|
* * This wrapper will check if there is an available node with the requested preset and if so checks for an available client ID to join with
|
||||||
|
*
|
||||||
|
* @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
|
||||||
|
* @returns
|
||||||
*/
|
*/
|
||||||
async function joinServerWrapper(presetName, channelId, clientIdsUsed) {
|
async function joinServerWrapper(presetName, channelId, clientIdsUsed) {
|
||||||
// Get nodes online
|
// Get nodes online
|
||||||
@@ -41,20 +46,27 @@ async function joinServerWrapper(presetName, channelId, clientIdsUsed) {
|
|||||||
// If so, join with the first node
|
// If so, join with the first node
|
||||||
var availableClientIds = await Object(JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json'))));
|
var availableClientIds = await Object(JSON.parse(readFileSync(path.resolve(__dirname, '../clientIds.json'))));
|
||||||
log.DEBUG("All clients: ", Object.keys(availableClientIds));
|
log.DEBUG("All clients: ", Object.keys(availableClientIds));
|
||||||
log.DEBUG("Client IDs Used: ", clientIdsUsed.keys());
|
|
||||||
for (const usedClientId of clientIdsUsed.keys()) {
|
var selectedClientId;
|
||||||
log.DEBUG("Used Client ID: ", usedClientId);
|
if (typeof clientIdsUsed === 'string') {
|
||||||
if (Object.keys(availableClientIds).includes(usedClientId)) {
|
if (Object.keys(availableClientIds).includes(clientIdsUsed)) selectedClientId = availableClientIds[clientIdsUsed];
|
||||||
delete availableClientIds[usedClientId];
|
}
|
||||||
|
else {
|
||||||
|
log.DEBUG("Client IDs Used: ", clientIdsUsed.keys());
|
||||||
|
for (const usedClientId of clientIdsUsed.keys()) {
|
||||||
|
log.DEBUG("Used Client ID: ", usedClientId);
|
||||||
|
if (Object.keys(availableClientIds).includes(usedClientId)) {
|
||||||
|
delete availableClientIds[usedClientId];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.DEBUG("Available Client IDs: ", availableClientIds);
|
||||||
|
|
||||||
|
if (!Object.keys(availableClientIds).length > 0) return log.ERROR("All client ID have been used, consider swapping one of the curretly joined bots or adding more Client IDs to the pool.")
|
||||||
|
selectedClientId = availableClientIds[Object.keys(availableClientIds)[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
log.DEBUG("Available Client IDs: ", availableClientIds);
|
|
||||||
|
|
||||||
if (!Object.keys(availableClientIds).length > 0) return log.ERROR("All client ID have been used, consider swapping one of the curretly joined bots or adding more Client IDs to the pool.")
|
|
||||||
|
|
||||||
const reqOptions = new requestOptions("/bot/join", "POST", nodesCurrentlyAvailable[0].ip, nodesCurrentlyAvailable[0].port);
|
const reqOptions = new requestOptions("/bot/join", "POST", nodesCurrentlyAvailable[0].ip, nodesCurrentlyAvailable[0].port);
|
||||||
const selectedClientId = availableClientIds[Object.keys(availableClientIds)[0]];
|
|
||||||
sendHttpRequest(reqOptions, JSON.stringify({
|
sendHttpRequest(reqOptions, JSON.stringify({
|
||||||
"channelId": channelId,
|
"channelId": channelId,
|
||||||
"clientId": selectedClientId.id,
|
"clientId": selectedClientId.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user