Automatically disable voice commands if Lavalink is missing

This commit is contained in:
TheEssem 2020-06-27 16:34:31 -05:00
parent 63277d9855
commit 7dbf6fdf2a
14 changed files with 44 additions and 13 deletions

View file

@ -2,12 +2,13 @@ const collections = require("./collections.js");
const logger = require("./logger.js");
// load command into memory
exports.load = async (command) => {
exports.load = async (command, soundStatus) => {
const props = require(`../commands/${command}`);
if (props.requires === "google" && process.env.GOOGLE === "") return logger.log("info", `Google info not provided in config, skipped loading command ${command}...`);
if (props.requires === "cat" && process.env.CAT === "") return logger.log("info", `Cat API info not provided in config, skipped loading command ${command}...`);
if (props.requires === "mashape" && process.env.MASHAPE === "") return logger.log("info", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
if (props.requires === "twitter" && process.env.TWITTER === "false") return logger.log("info", `Twitter bot disabled, skipped loading command ${command}...`);
if (props.requires === "sound" && soundStatus) return logger.log("info", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
collections.commands.set(command.split(".")[0], props.run);
collections.info.set(command.split(".")[0], {
category: props.category,

View file

@ -9,6 +9,23 @@ const nodes = [
let manager;
exports.status = false;
exports.checkStatus = async () => {
const statuses = [];
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);
} catch {
statuses.push(true);
}
}
const result = statuses.filter(Boolean);
this.status = result.length > 0 ? true : false;
return this.status;
};
exports.connect = async () => {
manager = new Manager(client, nodes, {
user: client.user.id