mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
Remix — the complete rewrite
Upgrades the bot from fluxerjs 2.2 to 3.0 and restructures everything into a layered architecture (~28K lines): Dependencies: - @fluxerjs/core, util, voice: ^2.2.0 -> ^3.0.0 (typed events, PartialMessage payloads, camelCase API) - @fluxerjs/sharding ^3.0.0 added — built-in sharding mode (shard.mjs, one process per shard) - @discordjs/opus dropped — opusscript + prism-media cover encoding Architecture: - commands: every command split into submodules (player, lastfm, settings, debug) with a shared CommandBuilder/Loader/Handler core - ui: embeds, paginators, help command, permission checks - voice: gateway event routing, rejoin/247 boot recovery, state resolver - music: player split into Queue/Search/Playback/Display mixins, stream pipeline + WebM/Opus muxer (no FFmpeg needed) - dashboard: Redis pub/sub, RPC handlers, serializers - db: MySQL manager + per-guild settings - services: LastFm manager split into focused mixins - utils: sharding, 24/7 helpers, API client Runtime fixes over v2: - Redis v5 reconnect: capped numeric backoff (0.5s ramp to 15s), never exhausts, auto-recovers when the server comes back - Redis main/subscriber clients connect in parallel; clean shutdown - Logger storm guard: identical error/warn lines deduped in a 60s window - self-deaf fix on voice join - config example uses redis://127.0.0.1 (avoids IPv6 ENETUNREACH) Housekeeping: dead code removed (Tuna.mjs + follow-redirects dep), .gitignore added (config.json, .env, node_modules, runtime state).
This commit is contained in:
1 parent
0f085a6ae4
commit
253d11cd57
150 files changed
+19935
-16894
No files matched your search
@@ -0,0 +1,236 @@
|
||||
/**
|
||||
* @module commands/debug/voiceDiagnostic
|
||||
* @description Full voice diagnostic renderer for the debug command. Verbatim from the original single-file command.
|
||||
*/
|
||||
|
||||
import { EmbedBuilder } from "@fluxerjs/core";
|
||||
import { logger } from "../../src/core/Logger.mjs";
|
||||
import { getGlobalColor, cleanId } from "../../src/ui/index.mjs";
|
||||
import { DANGER_COLOR, EMOJI_REMOVE_TIMEOUT } from "../../src/utils/UI.mjs";
|
||||
import { MAX_DESC } from "./consts.mjs";
|
||||
import {
|
||||
roomStateLabel, isGhostConnection, getBotGatewayVoiceState, isStaleGatewayPresence,
|
||||
} from "./gateway.mjs";
|
||||
|
||||
/**
|
||||
* Run a full voice diagnostic, displaying player states and ghost connections.
|
||||
* @private
|
||||
* @async
|
||||
* @param {object} msg - The command message wrapper.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
export async function runVoiceDiagnostic(msg) {
|
||||
const servers = [...this.players.playerMap.entries()].map(([cid, s]) => {
|
||||
const channel = this.client.channels.get(cid);
|
||||
const guildId = s._guildId ?? channel?.guildId ?? channel?.guild_id;
|
||||
const guild = guildId ? this.client.guilds.get(cleanId(guildId)) : null;
|
||||
const conn = s.connection;
|
||||
const room = conn?.room;
|
||||
const ghost = isGhostConnection(s);
|
||||
const staleGateway = ghost ? isStaleGatewayPresence(this.client, s) : false;
|
||||
const gatewayVoiceState = getBotGatewayVoiceState(this.client, guildId);
|
||||
return {
|
||||
name: channel?.name ?? "unknown",
|
||||
id: channel?.id ?? cid,
|
||||
channelId: s._channelId ?? cid,
|
||||
guildId: guildId ?? "unknown",
|
||||
guildname: guild?.name ?? channel?.guild?.name ?? "unknown",
|
||||
conn: conn ? "yes" : "null",
|
||||
connDestroyed: conn?._destroyed ?? null,
|
||||
roomConnected: room?.isConnected ?? null,
|
||||
roomState: roomStateLabel(room),
|
||||
mediaPlayer: !!s._mediaPlayer && !s._mediaPlayer?.destroyed ? "alive" : (s._mediaPlayer?.destroyed ? "destroyed" : "none"),
|
||||
destroyed: s._destroyed ?? false,
|
||||
leaving: s.leaving ?? false,
|
||||
joining: s._isJoining ?? false,
|
||||
recovering: s._isRecovering ?? false,
|
||||
paused: s._paused ?? false,
|
||||
hasQueue: !!(s.queue?.getCurrent() || !s.queue?.isEmpty()),
|
||||
home247: s._home247Channel ?? null,
|
||||
ghost,
|
||||
staleGateway,
|
||||
gatewayVoiceChannel: gatewayVoiceState?.channelId ?? null,
|
||||
};
|
||||
});
|
||||
const pending = [...(this.players._pendingJoins ?? [])];
|
||||
|
||||
const ghostConnections = servers.filter(s => s.ghost);
|
||||
const livePlayers = servers.filter(s => s.conn === "yes" && !s.destroyed && !s.leaving);
|
||||
const actuallyConnected = livePlayers.filter(s => !s.ghost);
|
||||
const channels247 = servers.filter(s => s.home247);
|
||||
|
||||
const summary = {
|
||||
playerMapSize: this.players.playerMap.size,
|
||||
livePlayers: livePlayers.length,
|
||||
actuallyConnected: actuallyConnected.length,
|
||||
ghostConnections: ghostConnections.length,
|
||||
channels247: channels247.length,
|
||||
pendingJoins: pending.length,
|
||||
pendingChannels: pending,
|
||||
};
|
||||
|
||||
const pages = [];
|
||||
|
||||
const summaryLines = [
|
||||
`📊 **Summary**`,
|
||||
`Players in map: **${summary.playerMapSize}**`,
|
||||
`Live players: **${summary.livePlayers}**`,
|
||||
`Actually connected: **${summary.actuallyConnected}**`,
|
||||
`Ghost connections: **${summary.ghostConnections}**`,
|
||||
`24/7 channels: **${summary.channels247}**`,
|
||||
`Pending joins: **${summary.pendingJoins}**${summary.pendingChannels.length ? ` (\`${summary.pendingChannels.join("`, `")}\`)` : ""}`,
|
||||
];
|
||||
|
||||
if (ghostConnections.length > 0) {
|
||||
summaryLines.push("", `👻 **Ghost Connections (${ghostConnections.length}):**`, "These players *appear* in voice but their WebSocket/LiveKit room is dead:");
|
||||
summaryLines.push(`Use \`%debug voice-rejoin\` to rejoin detected ghosts, or \`%debug 247-rejoin\` to force-rejoin all 24/7 channels.`);
|
||||
for (const g of ghostConnections) {
|
||||
const gatewayInfo = g.staleGateway
|
||||
? `gateway:stale(ch:${g.gatewayVoiceChannel ?? "?"})`
|
||||
: `gateway:present(ch:${g.gatewayVoiceChannel ?? "?"})`;
|
||||
const detail = ` 👻 \`${g.guildname}\` / \`#${g.name}\` — room:${g.roomState} connected:${g.roomConnected} media:${g.mediaPlayer} ${gatewayInfo} 247:${g.home247 ?? "no"}`;
|
||||
if (summaryLines.join("\n").length + detail.length + 1 > MAX_DESC - 60) {
|
||||
summaryLines.push(` … and more ghosts (see JSON details)`);
|
||||
break;
|
||||
}
|
||||
summaryLines.push(detail);
|
||||
}
|
||||
}
|
||||
|
||||
if (channels247.length > 0 && ghostConnections.length === 0) {
|
||||
summaryLines.push("", `ℹ️ **24/7 Channels (${channels247.length}):**`, `WebSocket deaths can leave 24/7 channels as invisible ghosts (room reports healthy but transport is dead).`);
|
||||
summaryLines.push(`Use \`%debug 247-rejoin\` to force-rejoin all 24/7 channels if you suspect ghost connections.`);
|
||||
}
|
||||
|
||||
summaryLines.push("", "**Players:**");
|
||||
for (let i = 0; i < servers.length; i++) {
|
||||
const s = servers[i];
|
||||
let status;
|
||||
if (s.ghost) {
|
||||
status = "👻";
|
||||
} else if (s.conn === "yes" && !s.destroyed && !s.leaving) {
|
||||
status = "🟢";
|
||||
} else {
|
||||
status = "🔴";
|
||||
}
|
||||
const ghostTag = s.ghost ? " ⚠️GHOST" : "";
|
||||
const staleTag = s.staleGateway ? " ⚠️STALE_GW" : "";
|
||||
const tag247 = s.home247 ? " 🔄247" : "";
|
||||
const line = `${status} \`${s.guildname}\` / \`#${s.name}\` — conn:${s.conn} room:${s.roomState} connected:${s.roomConnected} media:${s.mediaPlayer}${ghostTag}${staleTag}${tag247}`;
|
||||
if (summaryLines.join("\n").length + line.length + 1 > MAX_DESC - 30) {
|
||||
summaryLines.push(`… and ${servers.length - i} more (see next pages)`);
|
||||
break;
|
||||
}
|
||||
summaryLines.push(line);
|
||||
}
|
||||
pages.push(summaryLines.join("\n"));
|
||||
|
||||
let groupJson = "";
|
||||
for (let i = 0; i < servers.length; i++) {
|
||||
const singleJson = JSON.stringify(servers[i], null, 2);
|
||||
const candidate = groupJson
|
||||
? groupJson.slice(0, -1) + ",\n" + singleJson.slice(1)
|
||||
: singleJson;
|
||||
|
||||
const candidateLen = ("```json\n" + candidate + "\n```").length;
|
||||
|
||||
if (candidateLen > MAX_DESC && groupJson) {
|
||||
pages.push(("```json\n" + groupJson + "\n```").slice(0, MAX_DESC));
|
||||
groupJson = singleJson;
|
||||
} else if (candidateLen > MAX_DESC) {
|
||||
const budget = MAX_DESC - 12;
|
||||
pages.push(("```json\n" + singleJson.slice(0, budget) + "\n```").slice(0, MAX_DESC));
|
||||
groupJson = "";
|
||||
} else {
|
||||
groupJson = candidate;
|
||||
}
|
||||
}
|
||||
if (groupJson) {
|
||||
pages.push(("```json\n" + groupJson + "\n```").slice(0, MAX_DESC));
|
||||
}
|
||||
|
||||
if (pages.length === 1) {
|
||||
const embedColor = ghostConnections.length > 0 ? DANGER_COLOR : getGlobalColor();
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(embedColor)
|
||||
.setTitle(this.t(msg, "responses.debug.voiceTitle") + (ghostConnections.length > 0 ? ` — ${ghostConnections.length} Ghost(s) Detected!` : ""))
|
||||
.setDescription(pages[0].slice(0, MAX_DESC))
|
||||
;
|
||||
return msg.reply({ embeds: [embed] });
|
||||
}
|
||||
|
||||
const totalPages = pages.length;
|
||||
let currentPage = 0;
|
||||
|
||||
const buildPage = (pageIdx, expired = false) => {
|
||||
const isSummaryPage = pageIdx === 0;
|
||||
const pageLabel = isSummaryPage
|
||||
? "Summary"
|
||||
: `Player Detail${pages[pageIdx].split(`"name":`).length - 1 > 1 ? "s" : ""}`;
|
||||
const footerText = expired
|
||||
? this.t(msg, "responses._common.controlsExpired")
|
||||
: `${this.t(msg, "responses.debug.pageLabel", { page: pageIdx + 1, total: totalPages })} • ${this.t(msg, "responses.eval.navigateHint")}`;
|
||||
|
||||
const embedColor = (isSummaryPage && ghostConnections.length > 0) ? DANGER_COLOR : getGlobalColor();
|
||||
const titleSuffix = (isSummaryPage && ghostConnections.length > 0) ? ` — ${ghostConnections.length} Ghost(s) Detected!` : "";
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(embedColor)
|
||||
.setTitle(this.t(msg, "responses.debug.voiceTitle") + titleSuffix + ` — ${pageLabel}`)
|
||||
.setDescription(pages[pageIdx].slice(0, MAX_DESC))
|
||||
.setFooter({ text: footerText })
|
||||
;
|
||||
return { embeds: [embed] };
|
||||
};
|
||||
|
||||
const replyMsg = await msg.reply(buildPage(0));
|
||||
if (!replyMsg?.message) return;
|
||||
|
||||
const navEmojis = ["⬅️", "➡️", "❌"];
|
||||
for (const emoji of navEmojis) {
|
||||
await replyMsg.message.react(emoji).catch(() => {});
|
||||
}
|
||||
|
||||
const clearReactions = async () => {
|
||||
try {
|
||||
await replyMsg.message.removeAllReactions();
|
||||
} catch (e) {
|
||||
for (const emoji of navEmojis) {
|
||||
try { await replyMsg.message.removeReaction(emoji); } catch (err) { logger.warn("[Debug] removeReaction fallback:", err?.message); }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let emojiTimeout;
|
||||
const resetTimer = () => {
|
||||
clearTimeout(emojiTimeout);
|
||||
emojiTimeout = setTimeout(async () => {
|
||||
unobserve?.();
|
||||
await clearReactions();
|
||||
await replyMsg.edit(buildPage(currentPage, true)).catch(() => {});
|
||||
}, EMOJI_REMOVE_TIMEOUT);
|
||||
};
|
||||
|
||||
const unobserve = replyMsg.onReaction(navEmojis, async (e) => {
|
||||
const emoji = e?.emoji_id ?? e?.emoji?.id ?? e?.emoji;
|
||||
|
||||
if (emoji === "❌") {
|
||||
clearTimeout(emojiTimeout);
|
||||
unobserve?.();
|
||||
await replyMsg.message.delete().catch(() => {});
|
||||
return;
|
||||
}
|
||||
|
||||
resetTimer();
|
||||
|
||||
if (emoji === "⬅️") {
|
||||
currentPage = currentPage > 0 ? currentPage - 1 : totalPages - 1;
|
||||
} else if (emoji === "➡️") {
|
||||
currentPage = currentPage < totalPages - 1 ? currentPage + 1 : 0;
|
||||
}
|
||||
|
||||
await replyMsg.edit(buildPage(currentPage)).catch(() => {});
|
||||
});
|
||||
|
||||
resetTimer();
|
||||
}
|
||||
Reference in new issue
Block a user