Allow sound player to start even if some nodes are down, docker maintenance

This commit is contained in:
TheEssem 2020-12-11 16:46:05 -06:00
parent 0566dca06d
commit a1c24ea30d
4 changed files with 20 additions and 12 deletions

View file

@ -6,7 +6,7 @@ const moment = require("moment");
require("moment-duration-format");
const { Manager } = require("@lavacord/eris");
const nodes = require("../servers.json").lava;
let nodes = require("../servers.json").lava;
exports.players = new Map();
@ -20,17 +20,17 @@ exports.status = false;
exports.connected = false;
exports.checkStatus = async () => {
const statuses = [];
const newNodes = [];
for (const node of nodes) {
try {
const response = await fetch(`http://${node.host}:${node.port}/version`, { headers: { Authorization: node.password } }).then(res => res.text());
if (response) statuses.push(false);
if (response) newNodes.push(node);
} catch {
statuses.push(true);
logger.log(`Failed to get status of Lavalink node ${node.host}.`);
}
}
const result = statuses.filter(Boolean);
this.status = result.length > 0 ? true : false;
nodes = newNodes;
this.status = newNodes.length === 0 ? true : false;
return this.status;
};