diff --git a/app.js b/app.js index 9117f1c8..a51e9e73 100644 --- a/app.js +++ b/app.js @@ -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}`); } diff --git a/commands/boi.js b/commands/boi.js index 12bef619..5798414f 100644 --- a/commands/boi.js +++ b/commands/boi.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["boy", "neutron", "hugh"]; exports.category = 6; -exports.help = "Plays the \"boi\" sound effect"; \ No newline at end of file +exports.help = "Plays the \"boi\" sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/boom.js b/commands/boom.js index fa63fb43..2eb28bc0 100644 --- a/commands/boom.js +++ b/commands/boom.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["thud", "vine"]; exports.category = 6; -exports.help = "Plays the Vine boom sound effect"; \ No newline at end of file +exports.help = "Plays the Vine boom sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/bruh.js b/commands/bruh.js index 9bbf0cf7..e18a51d1 100644 --- a/commands/bruh.js +++ b/commands/bruh.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["bro"]; exports.category = 6; -exports.help = "Plays the \"bruh\" sound effect"; \ No newline at end of file +exports.help = "Plays the \"bruh\" sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/explosion.js b/commands/explosion.js index 0f083782..3ad64fe1 100644 --- a/commands/explosion.js +++ b/commands/explosion.js @@ -5,4 +5,5 @@ exports.run = async (message) => { }; exports.category = 6; -exports.help = "Plays an explosion sound effect"; \ No newline at end of file +exports.help = "Plays an explosion sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/fakeping.js b/commands/fakeping.js index b4b5be86..6ffe793d 100644 --- a/commands/fakeping.js +++ b/commands/fakeping.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["notification", "notif"]; exports.category = 6; -exports.help = "Plays a Discord ping sound effect"; \ No newline at end of file +exports.help = "Plays a Discord ping sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/fart.js b/commands/fart.js index c34f4155..d15e0a52 100644 --- a/commands/fart.js +++ b/commands/fart.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["toot"]; exports.category = 6; -exports.help = "Plays a fart sound effect"; \ No newline at end of file +exports.help = "Plays a fart sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/fbi.js b/commands/fbi.js index c0bc49c1..38b12301 100644 --- a/commands/fbi.js +++ b/commands/fbi.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["openup"]; exports.category = 6; -exports.help = "Plays the \"FBI OPEN UP\" sound effect"; \ No newline at end of file +exports.help = "Plays the \"FBI OPEN UP\" sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/mail.js b/commands/mail.js index d10563d9..e9be4c10 100644 --- a/commands/mail.js +++ b/commands/mail.js @@ -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"; \ No newline at end of file +exports.help = "Plays the \"You've got mail\" sound effect"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/oof.js b/commands/oof.js index ef05204c..91e3217f 100644 --- a/commands/oof.js +++ b/commands/oof.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["roblox", "commitdie"]; exports.category = 6; -exports.help = "Plays the Roblox \"oof\" sound"; \ No newline at end of file +exports.help = "Plays the Roblox \"oof\" sound"; +exports.requires = "sound"; \ No newline at end of file diff --git a/commands/winxp.js b/commands/winxp.js index 9eb702ee..49ad4d73 100644 --- a/commands/winxp.js +++ b/commands/winxp.js @@ -6,4 +6,5 @@ exports.run = async (message) => { exports.aliases = ["windows", "xp"]; exports.category = 6; -exports.help = "Plays the Windows XP startup sound"; \ No newline at end of file +exports.help = "Plays the Windows XP startup sound"; +exports.requires = "sound"; \ No newline at end of file diff --git a/events/ready.js b/events/ready.js index 48105a21..7921b46c 100644 --- a/events/ready.js +++ b/events/ready.js @@ -129,7 +129,7 @@ module.exports = async () => { }); }; - await soundPlayer.connect(); + if (!soundPlayer.status) await soundPlayer.connect(); // tweet stuff if (twitter !== null && twitter.active === false) { diff --git a/utils/handler.js b/utils/handler.js index cf22d39d..767f91b6 100644 --- a/utils/handler.js +++ b/utils/handler.js @@ -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, diff --git a/utils/soundplayer.js b/utils/soundplayer.js index 0a82784b..a98ff892 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -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