mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-23 21:52:45 -05:00
testing this for a day if its bad i just wast my time
This commit is contained in:
1 parent
fd58343ce9
commit
656cbfe149
33 files changed
+726
-102
No files matched your search
+18
-4
@@ -25,6 +25,7 @@ import { LavalinkManager } from "../music/LavalinkManager.mjs";
|
||||
import { Dashboard } from "../dashboard/Dashboard.mjs";
|
||||
import { VoiceStateCache } from "../voice/VoiceStateCache.mjs";
|
||||
import { GatewayHandler } from "../voice/gateway/GatewayHandler.mjs";
|
||||
import { RejoinBackoff } from "../voice/gateway/RejoinBackoff.mjs";
|
||||
import { LastFmManager } from "../services/lastfm/LastFmManager.mjs";
|
||||
import { FluxerListManager } from "../services/FluxerListManager.mjs";
|
||||
import { TrackOptionsManager } from "../services/TrackOptionsManager.mjs";
|
||||
@@ -220,7 +221,12 @@ class Remix {
|
||||
}
|
||||
);
|
||||
};
|
||||
commands.owners = config.owners ?? [];
|
||||
const ownerList = [].concat(config.owners ?? []);
|
||||
if (ownerList.some((id) => typeof id === "number")) {
|
||||
logger.warn("[Config] owners contains a JSON number. Snowflake IDs exceed 2^53 and are corrupted as numbers: write each ID as a quoted string.");
|
||||
}
|
||||
commands.owners = ownerList.map((id) => String(id).trim()).filter(Boolean);
|
||||
commands.allowBotCommands = config.allowBotCommands === true;
|
||||
|
||||
this.lavalink = null;
|
||||
let lavalinkInitialised = false;
|
||||
@@ -241,6 +247,8 @@ class Remix {
|
||||
this.intentionalLeaves = new Map();
|
||||
/** Bot-level 24/7 rejoin timers (channelId → Timeout). Owned by Remix, not by Players. */
|
||||
this._247RejoinTimers = new Map();
|
||||
/** Escalating per-channel cool-down so the 24/7 watchdog stops hammering channels it cannot join. */
|
||||
this.rejoinBackoff = new RejoinBackoff();
|
||||
|
||||
this.gatewayHandler = new GatewayHandler(this);
|
||||
this.gatewayHandler.setupEventHandlers();
|
||||
@@ -333,9 +341,15 @@ class Remix {
|
||||
this.comHash = childProcess.execSync("git rev-parse --short HEAD", { cwd: __dirname, timeout: 3000 }).toString().trim();
|
||||
this.comHashLong = childProcess.execSync("git rev-parse HEAD", { cwd: __dirname, timeout: 3000 }).toString().trim();
|
||||
} catch (e) {
|
||||
logger.warn("[Git] comhash error:", e?.message);
|
||||
this.comHash = "Newest";
|
||||
this.comHashLong = null;
|
||||
const sha = process.env.GIT_SHA?.trim();
|
||||
if (sha) {
|
||||
this.comHash = sha.slice(0, 7);
|
||||
this.comHashLong = sha;
|
||||
} else {
|
||||
logger.warn("[Git] comhash error:", e?.message);
|
||||
this.comHash = "Newest";
|
||||
this.comHashLong = null;
|
||||
}
|
||||
}
|
||||
|
||||
this.comLink = "https://github.com/remix-bot/fluxer/commit/" + (this.comHashLong ?? "");
|
||||
|
||||
@@ -17,6 +17,15 @@ import { remove247ChannelMode, isPlayerConnectionDead, detachPlayerFromManager,
|
||||
import { logger } from "./Logger.mjs";
|
||||
import { Dashboard } from "../dashboard/Dashboard.mjs";
|
||||
|
||||
/** Reject if `promise` has not settled within `ms` (the timer is always cleared). */
|
||||
function withTimeout(promise, ms, label) {
|
||||
let timer;
|
||||
return Promise.race([
|
||||
promise,
|
||||
new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms); }),
|
||||
]).finally(() => clearTimeout(timer));
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {object}
|
||||
* @description Voice/channel mixin — applied to Remix.
|
||||
@@ -390,6 +399,7 @@ const BotVoiceMixin = {
|
||||
|
||||
this.players.playerMap.set(cleanChannelId, player);
|
||||
this.players._indexPlayer(cleanGuildId, cleanChannelId);
|
||||
this.rejoinBackoff?.recordSuccess(cleanChannelId);
|
||||
if (this.players._pendingJoins) {
|
||||
this.players._pendingJoins.delete(cleanChannelId);
|
||||
}
|
||||
@@ -444,9 +454,29 @@ const BotVoiceMixin = {
|
||||
logger.player(`[Restore] ${rows.length} saved player(s) found — restoring ${local.length} on this shard.`);
|
||||
if (!local.length) return;
|
||||
|
||||
for (let i = 0; i < local.length; i++) {
|
||||
const { guildId, data: snap } = local[i];
|
||||
if (i > 0) await new Promise((r) => setTimeout(r, 1_500));
|
||||
const rc = this.config?.restore ?? {};
|
||||
const num = (v, d) => (Number.isFinite(Number(v)) && Number(v) >= 0 ? Number(v) : d);
|
||||
const spacingMs = num(rc.spacingMs, 1_500);
|
||||
const startTimeoutMs = num(rc.startTimeoutMs, 20_000);
|
||||
const seekSettleMs = num(rc.seekSettleMs, 800);
|
||||
const spawnTimeoutMs = num(rc.spawnTimeoutMs, 60_000);
|
||||
const rawHours = Number(rc.maxAgeHours);
|
||||
const maxAgeHours = rawHours > 0 ? rawHours : 12;
|
||||
|
||||
const toRestore = [];
|
||||
for (const r of local) {
|
||||
if (Number.isFinite(r.ageMs) && r.ageMs > maxAgeHours * 3_600_000) {
|
||||
logger.player(`[Restore] Snapshot for guild ${r.guildId} is ${(r.ageMs / 3_600_000).toFixed(1)}h old (limit ${maxAgeHours}h), dropping it.`);
|
||||
try { await store.clearSnapshot(r.guildId); } catch (_) {}
|
||||
} else {
|
||||
toRestore.push(r);
|
||||
}
|
||||
}
|
||||
if (!toRestore.length) return;
|
||||
|
||||
for (let i = 0; i < toRestore.length; i++) {
|
||||
const { guildId, data: snap } = toRestore[i];
|
||||
if (i > 0) await new Promise((r) => setTimeout(r, spacingMs));
|
||||
|
||||
try {
|
||||
const channelId = cleanId(snap.channelId);
|
||||
@@ -459,7 +489,7 @@ const BotVoiceMixin = {
|
||||
continue;
|
||||
}
|
||||
|
||||
const player = await this._spawnPlayer(guildId, channelId);
|
||||
const player = await withTimeout(this._spawnPlayer(guildId, channelId), spawnTimeoutMs, "Voice join");
|
||||
|
||||
const tcId = cleanId(snap.textChannelId);
|
||||
if (tcId) {
|
||||
@@ -497,11 +527,25 @@ const BotVoiceMixin = {
|
||||
system: true,
|
||||
});
|
||||
|
||||
await player.playNext();
|
||||
await new Promise((resolve) => {
|
||||
const timer = setTimeout(() => { player.off("startplay", onStart); resolve(); }, startTimeoutMs);
|
||||
const onStart = () => { clearTimeout(timer); player.off("startplay", onStart); resolve(); };
|
||||
player.once("startplay", onStart);
|
||||
player.playNext().then(onStart, (e) => {
|
||||
logger.warn(`[Restore] playNext failed for guild ${guildId}:`, e?.message ?? e);
|
||||
onStart();
|
||||
});
|
||||
});
|
||||
|
||||
if (current && pos > 0 && dur > 0) {
|
||||
await new Promise((r) => setTimeout(r, 800)); // let the bridge settle
|
||||
try { await player.seekToPosition(pos); } catch (_) {}
|
||||
(async () => {
|
||||
const deadline = Date.now() + 15_000;
|
||||
while (Date.now() < deadline && player._audioBridge?._playing !== true) {
|
||||
await new Promise((r) => setTimeout(r, 250));
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, seekSettleMs)); // let the bridge settle
|
||||
try { await player.seekToPosition(pos); } catch (_) {}
|
||||
})().catch(() => {});
|
||||
}
|
||||
|
||||
logger.player(`[Restore] Guild ${guildId}: ${player.queue.data.length} track(s) restored, resuming at ${pos}ms.`);
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* @module src/core/Heartbeat
|
||||
* @description Liveness heartbeat for the container HEALTHCHECK.
|
||||
*
|
||||
* The old healthcheck was `pgrep -f "node .*index.mjs"`, which (a) needs `procps`, not present in
|
||||
* the slim Node image, and (b) can only say "the process exists", never "the bot is working". This
|
||||
* writes a timestamp to a file every few seconds, but only while the Node event loop is actually
|
||||
* running timers AND the bot is logged in. `docker/healthcheck.mjs` fails when the file is missing
|
||||
* or stale, so a blocked event loop or a bot that never logged in now shows up as unhealthy.
|
||||
* It does nothing unless HEARTBEAT_FILE is set (the Dockerfile sets it).
|
||||
*/
|
||||
import { writeFile } from "node:fs";
|
||||
|
||||
/**
|
||||
* @param {object} [o]
|
||||
* @param {string} [o.file=process.env.HEARTBEAT_FILE] - Heartbeat file; no file means no heartbeat.
|
||||
* @param {number} [o.intervalMs=15000]
|
||||
* @param {() => boolean} [o.isReady] - Only beat while this returns true (e.g. "logged in").
|
||||
* @param {() => number} [o.now]
|
||||
* @returns {NodeJS.Timeout|null} The (unref'd) interval, or null when disabled.
|
||||
*/
|
||||
export function startHeartbeat({ file = process.env.HEARTBEAT_FILE, intervalMs = 15_000, isReady = () => true, now = Date.now } = {}) {
|
||||
if (!file) return null;
|
||||
const beat = () => {
|
||||
let ready = false;
|
||||
try { ready = Boolean(isReady()); } catch (_) {}
|
||||
if (ready) writeFile(file, String(now()), () => {});
|
||||
};
|
||||
beat();
|
||||
const timer = setInterval(beat, intervalMs);
|
||||
timer.unref?.();
|
||||
return timer;
|
||||
}
|
||||
|
||||
export default { startHeartbeat };
|
||||
Reference in new issue
Block a user