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

5
app.js
View file

@ -9,16 +9,19 @@ const logger = require("./utils/logger.js");
const client = require("./utils/client.js");
// initialize command loader
const handler = require("./utils/handler.js");
const sound = require("./utils/soundplayer.js");
// registers stuff and connects the bot
async function init() {
logger.log("info", "Starting esmBot...");
// register commands and their info
const commands = await readdir("./commands/");
const soundStatus = await sound.checkStatus();
logger.log("info", `Attempting to load ${commands.length} commands...`);
for (const commandFile of commands) {
logger.log("info", `Loading command ${commandFile}...`);
try {
await handler.load(commandFile);
await handler.load(commandFile, soundStatus);
} catch (e) {
logger.error(`Failed to register command ${commandFile.split(".")[0]}: ${e}`);
}

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["boy", "neutron", "hugh"];
exports.category = 6;
exports.help = "Plays the \"boi\" sound effect";
exports.help = "Plays the \"boi\" sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["thud", "vine"];
exports.category = 6;
exports.help = "Plays the Vine boom sound effect";
exports.help = "Plays the Vine boom sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["bro"];
exports.category = 6;
exports.help = "Plays the \"bruh\" sound effect";
exports.help = "Plays the \"bruh\" sound effect";
exports.requires = "sound";

View file

@ -5,4 +5,5 @@ exports.run = async (message) => {
};
exports.category = 6;
exports.help = "Plays an explosion sound effect";
exports.help = "Plays an explosion sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["notification", "notif"];
exports.category = 6;
exports.help = "Plays a Discord ping sound effect";
exports.help = "Plays a Discord ping sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["toot"];
exports.category = 6;
exports.help = "Plays a fart sound effect";
exports.help = "Plays a fart sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["openup"];
exports.category = 6;
exports.help = "Plays the \"FBI OPEN UP\" sound effect";
exports.help = "Plays the \"FBI OPEN UP\" sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["yougotmail", "youvegotmail", "aol"];
exports.category = 6;
exports.help = "Plays the \"You've got mail\" sound effect";
exports.help = "Plays the \"You've got mail\" sound effect";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["roblox", "commitdie"];
exports.category = 6;
exports.help = "Plays the Roblox \"oof\" sound";
exports.help = "Plays the Roblox \"oof\" sound";
exports.requires = "sound";

View file

@ -6,4 +6,5 @@ exports.run = async (message) => {
exports.aliases = ["windows", "xp"];
exports.category = 6;
exports.help = "Plays the Windows XP startup sound";
exports.help = "Plays the Windows XP startup sound";
exports.requires = "sound";

View file

@ -129,7 +129,7 @@ module.exports = async () => {
});
};
await soundPlayer.connect();
if (!soundPlayer.status) await soundPlayer.connect();
// tweet stuff
if (twitter !== null && twitter.active === false) {

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