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:
NoLogicAlan committed 2026-09-09 02:04:33 +03:00
1 parent 0f085a6ae4
commit 253d11cd57
150 files changed
+19935 -16894

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
/**
* @module commands/player/consts
* @description Pure display constants for the player control panel: state
* emoji indicators, control button definitions and progress-bar characters.
*/
/** @type {Object.<string, string>} Emoji indicators for player states. */
export const STATES = {
playing: "🎵",
paused: "⏸️",
stopped: "🔇",
loading: "⏳"
};
/** @type {Object.<string, {emoji: string, action: string, desc: string}>} Available control button definitions. */
export const CONTROLS = {
prev: { emoji: "⏮️", action: "previous", desc: "Previous" },
play: { emoji: "▶️", action: "resume", desc: "Play" },
pause: { emoji: "⏸️", action: "pause", desc: "Pause" },
stop: { emoji: "⏹️", action: "stop", desc: "Stop" },
next: { emoji: "⏭️", action: "skip", desc: "Skip" },
loop: { emoji: "🔁", action: "loop", desc: "Loop" },
shuffle: { emoji: "🔀", action: "shuffle", desc: "Shuffle" },
volDown: { emoji: "🔉", action: "voldown", desc: "Volume Down" },
volUp: { emoji: "🔊", action: "volup", desc: "Volume Up" },
lyrics: { emoji: "📜", action: "lyrics", desc: "Lyrics" },
filter: { emoji: "🎛️", action: "filter", desc: "Audio Filters" },
close: { emoji: "❌", action: "close", desc: "Close" }
};
/** @type {Object.<string, string>} Progress bar character set. */
export const PROGRESS = {
filled: "▰",
empty: "▱",
indicator: "●",
start: "▏",
end: "▕"
};
+96
View File
@@ -0,0 +1,96 @@
/**
* @module commands/player/embed
* @description Player panel embed construction: state emoji, progress bar,
* volume gauge, loop/filter status and footer (verbatim body of the original
* run() closure, with the bot instance passed explicitly instead of `this`).
*/
import { Utils } from "../../src/utils/Utils.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../../src/ui/index.mjs";
import { STATES, PROGRESS } from "./consts.mjs";
/**
* Build the player panel embed with current state, progress, volume, and loop info.
* @param {object} bot - The bot instance (used for locale translation).
* @param {object} msg - The command message wrapper.
* @param {object} player - The guild player.
* @param {number} timeout - Session timeout in ms (shown in the footer area).
* @param {object} [state={}] - Optional state override with a message field.
* @returns {EmbedBuilder} The constructed embed builder.
*/
export function buildPlayerEmbed(bot, msg, player, timeout, state = {}) {
const current = player.queue.getCurrent();
const isPlaying = !player.paused && current;
const statusEmoji = isPlaying ? STATES.playing : player.paused ? STATES.paused : STATES.stopped;
let progressBar = "";
let timeDisplay = "`0:00 / 0:00`";
if (current?.duration && player.startedPlaying) {
const elapsed = Date.now() - player.startedPlaying;
const totalMs = typeof current.duration === "object"
? (current.duration.seconds ?? 0) * 1000
: current.duration;
const bar = Utils.progressBar(elapsed, totalMs, 20, PROGRESS.filled, PROGRESS.empty, isPlaying ? PROGRESS.indicator : PROGRESS.filled);
progressBar = PROGRESS.start + bar + PROGRESS.end;
const elapsedStr = Utils.prettifyMS(elapsed);
const totalStr = Utils.prettifyMS(totalMs);
timeDisplay = `\`${elapsedStr} / ${totalStr}\``;
} else {
progressBar = PROGRESS.start + PROGRESS.empty.repeat(20) + PROGRESS.end;
}
const volPercent = Math.round((player.preferredVolume ?? 1) * 100);
const volBars = Math.ceil(volPercent / 10);
const volumeBar = "█".repeat(volBars) + "░".repeat(10 - volBars);
const queueSize = player.queue.size();
const loopStatus = player.queue.songLoop ? bot.t(msg, "responses.player.loopSong") : player.queue.loop ? bot.t(msg, "responses.player.loopQueue") : bot.t(msg, "responses.player.loopOff");
let filterStatus = bot.t(msg, "responses.player.filterOff");
if (player.activeFilter) {
if (player.activeFilter.label.includes("+")) {
filterStatus = `🔥 **${player.activeFilter.label}**`;
} else {
filterStatus = `${player.activeFilter.emoji ?? "🎛️"} **${player.activeFilter.label}**`;
}
}
const nowPlaying = current
? `[${Utils.truncate(current.title, 45)}](${current.spotifyUrl || current.url})`
: bot.t(msg, "responses.filter.nothingPlayingInline");
const description = [
`${statusEmoji} ${bot.t(msg, "responses.player.nowPlayingLabel")}`,
`${nowPlaying}`,
``,
`${progressBar}`,
`${timeDisplay}`,
``,
bot.t(msg, "responses.player.volumeLabel", { volume: volPercent }) + " " + volumeBar,
`${bot.t(msg, "responses.player.queueLabel", { count: queueSize })} | Loop: ${loopStatus} | Filter: ${filterStatus}`,
``,
state.message ? `💬 *${state.message}*` : `💡 *${bot.t(msg, "responses.player.reactHint")}*`,
``,
bot.t(msg, "responses.player.sessionExpires", { minutes: Math.ceil(timeout / 60000) })
].join("\n");
const avatarUrl = typeof msg.author?.avatarURL === "function"
? msg.author.avatarURL()
: msg.author?.avatarURL ?? null;
const builder = new EmbedBuilder()
.setColor(getGlobalColor())
.setTitle(bot.t(msg, "responses.player.title"))
.setDescription(description)
.setFooter({
text: bot.t(msg, "responses.player.requestedBy", { username: msg.author?.username || "Unknown" }),
iconURL: avatarUrl
});
if (typeof builder.setTimestamp === "function") builder.setTimestamp();
if (current?.thumbnail) builder.setThumbnail(current.thumbnail);
return builder;
}
+10
View File
@@ -0,0 +1,10 @@
/**
* @module commands/player
* @description Barrel for the player control-panel implementation modules.
* commands/player.mjs (the command entry file) imports through this barrel;
* it stays the single import surface for the group.
*/
export { STATES, CONTROLS, PROGRESS } from "./consts.mjs";
export { buildPlayerEmbed } from "./embed.mjs";
export { openLyricsViewer, clearLyricsReactions } from "./lyrics.mjs";
+166
View File
@@ -0,0 +1,166 @@
/**
* @module commands/player/lyrics
* @description Embedded lyrics viewer for the player panel (verbatim body of
* the original "lyrics" reaction case): paginated lyric pages with navigation
* reactions, control-expiry timer and close handling. Session-scoped mutable
* state lives in the shared `session` object ({activeLyricsMsg, unobserve,
* emojiTimeout}) so the panel's closeSession can clean it up.
*/
import { Utils } from "../../src/utils/Utils.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
import { getGlobalColor } from "../../src/ui/index.mjs";
import { EMOJI_REMOVE_TIMEOUT } from "../../src/utils/UI.mjs";
import { logger } from "../../src/core/Logger.mjs";
/**
* Remove navigation reactions from a lyrics message.
* @param {object} lyricsMsg - The wrapped lyrics message with a .message property.
* @returns {Promise<void>}
*/
export async function clearLyricsReactions(lyricsMsg) {
if (!lyricsMsg?.message) return;
try {
await lyricsMsg.message.removeAllReactions();
} catch (e) {
for (const emoji of ["⬅️", "➡️", "❌"]) {
try {
await lyricsMsg.message.removeReaction(emoji);
} catch(e) { logger.warn("[Player] Error:", e?.message); }
}
}
}
/**
* Open (or reopen) the lyrics viewer for the player's current track.
*
* Mirrors the original `case "lyrics":` flow exactly: announces fetching,
* tears down a previous viewer, fetches lyrics from the player, renders
* paginated content, wires navigation/close reactions with the shared
* emoji-expiry timer, and returns the final reply string. Every exit path
* corresponds to `shouldUpdate = true` in the original switch, so the caller
* always refreshes the panel afterwards.
*
* @param {object} bot - The bot instance (locale translation via bot.t).
* @param {object} msg - The command message wrapper.
* @param {object} player - The guild player (player.lyrics(), queue).
* @param {function} refresh - Panel refresh callback ({ message }) => void.
* @param {object} session - Shared viewer state: { activeLyricsMsg, unobserve, emojiTimeout }.
* @returns {Promise<string>} The reply message text to surface on the panel.
*/
export async function openLyricsViewer(bot, msg, player, refresh, session) {
let reply = bot.t(msg, "responses.player.fetchingLyrics");
refresh({ message: reply });
try {
if (session.unobserve) {
session.unobserve();
clearTimeout(session.emojiTimeout);
if (session.activeLyricsMsg) await clearLyricsReactions(session.activeLyricsMsg);
}
const lyricsResult = await player.lyrics();
if (!lyricsResult) {
return bot.t(msg, "responses.player.noLyricsFound");
}
const syncBadge = lyricsResult.synced ? " ⏱️ Synced" : "";
const lines = lyricsResult.text.split('\n');
const totalLines = lines.length;
const LINES_PER_PAGE = 25;
const totalPages = Math.ceil(totalLines / LINES_PER_PAGE);
const pages = [];
for (let i = 0; i < totalLines; i += LINES_PER_PAGE) {
pages.push(lines.slice(i, i + LINES_PER_PAGE).join('\n'));
}
let currentPage = 0;
const buildLyricsContent = (pageIdx, expired = false, closed = false) => {
const title = Utils.truncate(
player.queue.getCurrent()?.title?.replace(/\(Official.*?\)/gi, '').trim() ?? '',
50
);
const footerText = closed
? `👋 Lyrics closed • NodeLink • ${totalLines} lines`
: expired
? `⌛ Controls expired • NodeLink • ${totalLines} lines`
: `NodeLink • ${totalLines} lines total${lyricsResult.synced ? ' • Synced' : ''}`;
const desc = [
`**${title}**${syncBadge} • Page ${pageIdx + 1}/${totalPages}`,
``,
'```',
pages[pageIdx],
totalPages > 1 && !expired && !closed ? `\n\n💡 ⬅️ ➡️ Navigate • ❌ Close` : '',
'```'
].join('\n');
return { embeds: [new EmbedBuilder().setColor(getGlobalColor()).setDescription(desc).setFooter({ text: footerText })] };
};
session.activeLyricsMsg = await msg.reply(buildLyricsContent(0));
if (session.activeLyricsMsg?.message && totalPages > 1) {
const navEmojis = ["⬅️", "➡️", "❌"];
for (const emoji of navEmojis) {
await session.activeLyricsMsg.message.react(emoji).catch(() => {});
}
const resetLyricsTimer = () => {
clearTimeout(session.emojiTimeout);
session.emojiTimeout = setTimeout(async () => {
await clearLyricsReactions(session.activeLyricsMsg);
await session.activeLyricsMsg.edit(buildLyricsContent(currentPage, true, false)).catch(() => {});
}, EMOJI_REMOVE_TIMEOUT);
};
session.unobserve = session.activeLyricsMsg.onReaction(navEmojis, async (e) => {
if (e.emoji_id === "❌") {
session.unobserve();
clearTimeout(session.emojiTimeout);
await clearLyricsReactions(session.activeLyricsMsg);
await session.activeLyricsMsg.edit(buildLyricsContent(currentPage, false, true)).catch(() => {});
return;
}
resetLyricsTimer();
if (e.emoji_id === "⬅️") {
currentPage = currentPage > 0 ? currentPage - 1 : totalPages - 1;
} else if (e.emoji_id === "➡️") {
currentPage = currentPage < totalPages - 1 ? currentPage + 1 : 0;
}
await session.activeLyricsMsg.edit(buildLyricsContent(currentPage));
});
resetLyricsTimer();
} else if (session.activeLyricsMsg?.message) {
await session.activeLyricsMsg.message.react("❌").catch(() => {});
const resetLyricsTimer = () => {
clearTimeout(session.emojiTimeout);
session.emojiTimeout = setTimeout(async () => {
await clearLyricsReactions(session.activeLyricsMsg);
await session.activeLyricsMsg.edit(buildLyricsContent(0, true, false)).catch(() => {});
}, EMOJI_REMOVE_TIMEOUT);
};
session.unobserve = session.activeLyricsMsg.onReaction(["❌"], async (e) => {
if (e.emoji_id === "❌") {
session.unobserve();
clearTimeout(session.emojiTimeout);
await clearLyricsReactions(session.activeLyricsMsg);
await session.activeLyricsMsg.edit(buildLyricsContent(0, false, true)).catch(() => {});
}
});
resetLyricsTimer();
}
return bot.t(msg, "responses.player.lyricsDisplayed", { lines: totalLines, pages: totalPages });
} catch (err) {
return bot.t(msg, "responses.player.lyricsError", { error: Utils.truncate(err.message, 50) });
}
}