Files
fluxer/commands/player/embed.mjs
T
NoLogicAlan 253d11cd57 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).
2026-09-09 02:04:33 +03:00

97 lines
4.0 KiB
JavaScript

/**
* @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;
}