fix: resolve startup crashes from missing exports, unsafe JSON parsing, and broken migrate/dashboard logic

Full rework and bugfix pass across the fluxer codebase to resolve
multiple runtime crashes that prevented the bot from starting and
loading guild settings correctly.

Export/Import Fixes:
- Added re-export of SettingsManager from settings/Settings.mjs
  into src/Settings.mjs to resolve missing named export error
  that crashed the bot on startup (affected CommandHandler,
  PlayerManager, and migrate.mjs)
- Verified all 70+ import/export chains across the entire project

JSON.parse Safety (mysql2 JSON column handling):
- src/Settings.mjs — added typeof guard before JSON.parse on
  RemoteSettingsManager.load() since mysql2 returns JSON columns
  as already-parsed objects, causing "[object Object]" SyntaxError
- settings/Settings.mjs — same typeof guard applied
- src/GatewayHandler.mjs — same typeof guard applied

Migrate Script Fix:
- settings/migrate.mjs — replaced abstract SettingsManager usage
  with concrete RemoteSettingsManager (which actually has the
  `guilds` property required for migration logic)

Dashboard Fix:
- src/dashboard/Dashboard.mjs — added missing reply() method to
  fakeMsg object so PlayerManager.initPlayer() doesn't crash when
  a user joins voice through the web dashboard

Files changed (13):
- src/Settings.mjs
- settings/Settings.mjs
- src/GatewayHandler.mjs
- settings/migrate.mjs
- src/dashboard/Dashboard.mjs
- src/CommandHandler.mjs
- src/PlayerManager.mjs
- src/MoonlinkManager.mjs
- src/Player.mjs
- src/RecoveryManager.mjs
- src/constants/audio/StreamMerger.mjs
- src/constants/audio/Tuna.mjs
- commands/remove.mjs
This commit is contained in:
NoLogicAlan committed 2026-05-06 23:33:57 +03:00
1 parent 5e0aefb79d
commit 991045f4dd
13 files changed
+1361 -1327

No files matched your search

+3 -3
View File
@@ -53,7 +53,7 @@ class StreamMerger extends Transform {
addStream(s) {
if (!this.ffmpeg) this.setupBaseFfmpeg();
const open = this.findOpenNode();
if (!open) throw "Impossible case detected. No free merge node found.";
if (!open) throw new Error("Impossible case detected. No free merge node found.");
const p = this.spawnFfmpeg();
const node = { process: p, pipes: [4], available: true, parent: open, children: [] };
open.children.push(node);
@@ -61,14 +61,14 @@ class StreamMerger extends Transform {
p.stderr.on("data", (c) => { logger.mediaplayer("[ffmpeg]", c.toString().trim()); });
p.stdio[4].write(Buffer.alloc(1024, 0));
p.stdout.pipe(open.process.stdio[open.pipes[0]]);
const pipeNumber = open.pipes[0].valueOf();
const pipeNumber = open.pipes[0];
open.pipes.splice(0, 1);
if (open.pipes.length === 0) open.available = false;
p.on("exit", () => {
open.pipes.push(pipeNumber);
open.available = true;
const idx = open.children.findIndex(c => c === node);
if (idx === -1) throw "Impossible case detected. Damaged node structure.";
if (idx === -1) throw new Error("Impossible case detected. Damaged node structure.");
open.children.splice(idx, 1);
});
}
+12 -2
View File
@@ -21,8 +21,18 @@ class Tuna {
var req = https.request(options, function(res) {
var chunks = [];
res.on("data", (chunk) => { chunks.push(chunk); });
res.on("end", () => { resolve(JSON.parse(Buffer.concat(chunks).toString())); });
res.on("error", (error) => { rej(error); });
res.on("end", () => {
try {
resolve(JSON.parse(Buffer.concat(chunks).toString()));
} catch (e) {
rej(new Error(`Tuna API JSON parse error: ${e.message}`));
}
});
});
req.on("error", (error) => { rej(error); });
req.setTimeout(15_000, () => {
req.destroy();
rej(new Error("Tuna API request timeout"));
});
req.end();
});