Make soundreload apply to all clusters

This commit is contained in:
TheEssem 2021-05-22 10:10:42 -05:00
parent 55a150c0c9
commit 96f8ec6353
No known key found for this signature in database
GPG Key ID: A3F9F02129092FCA
4 changed files with 35 additions and 16 deletions

@ -1 +1 @@
Subproject commit b26219baeb920506e40bc6db42fcde609fb499c7 Subproject commit e2887e42da18273f2c2eaac1ae5a973111434c90

View File

@ -1,16 +1,23 @@
const soundPlayer = require("../../utils/soundplayer.js");
const Command = require("../../classes/command.js"); const Command = require("../../classes/command.js");
class SoundReloadCommand extends Command { class SoundReloadCommand extends Command {
async run() { // another very hacky command
run() {
return new Promise((resolve) => {
if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can reload Lavalink!"; if (this.message.author.id !== process.env.OWNER) return "Only the bot owner can reload Lavalink!";
const soundStatus = await soundPlayer.checkStatus(); this.message.channel.sendTyping();
if (!soundStatus) { this.ipc.broadcast("soundreload");
const length = await soundPlayer.connect(this.client); this.ipc.register("soundReloadSuccess", (msg) => {
return `Successfully connected to ${length} Lavalink node(s).`; this.ipc.unregister("soundReloadSuccess");
} else { this.ipc.unregister("soundReloadFail");
return "I couldn't connect to any Lavalink nodes!"; resolve(`Successfully connected to ${msg.length} Lavalink node(s).`);
} });
this.ipc.register("soundReloadFail", () => {
this.ipc.unregister("soundReloadSuccess");
this.ipc.unregister("soundReloadFail");
resolve("I couldn't connect to any Lavalink nodes!");
});
});
} }
static description = "Attempts to reconnect to all available Lavalink nodes"; static description = "Attempts to reconnect to all available Lavalink nodes";

View File

@ -153,6 +153,16 @@ connected_workers ${image.connections.length}
return this.ipc.broadcast("reloadSuccess"); return this.ipc.broadcast("reloadSuccess");
}); });
this.ipc.register("soundreload", async () => {
const soundStatus = await sound.checkStatus();
if (!soundStatus) {
const length = await sound.connect(this.bot);
return this.ipc.broadcast("soundReloadSuccess", { length });
} else {
return this.ipc.broadcast("soundReloadFail");
}
});
// connect to lavalink // connect to lavalink
if (!sound.status && !sound.connected) await sound.connect(this.bot); if (!sound.status && !sound.connected) await sound.connect(this.bot);

View File

@ -232,9 +232,11 @@ exports.getType = async (image) => {
controller.abort(); controller.abort();
}, 25000); }, 25000);
try { try {
const imageRequest = await fetch(image, { signal: controller.signal, headers: { const imageRequest = await fetch(image, {
signal: controller.signal, headers: {
"Range": "bytes=0-1023" "Range": "bytes=0-1023"
}}); }
});
clearTimeout(timeout); clearTimeout(timeout);
const size = imageRequest.headers.has("Content-Range") ? imageRequest.headers.get("Content-Range").split("/")[1] : imageRequest.headers.get("Content-Length"); const size = imageRequest.headers.has("Content-Range") ? imageRequest.headers.get("Content-Range").split("/")[1] : imageRequest.headers.get("Content-Length");
if (parseInt(size) > 20971520) { if (parseInt(size) > 20971520) {