mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
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).
108 lines
3.8 KiB
JavaScript
108 lines
3.8 KiB
JavaScript
/**
|
|
* @module commands/list
|
|
* @description List the songs in the queue of the current voice channel with pagination.
|
|
*/
|
|
|
|
import { CommandBuilder } from "../src/commands/index.mjs";
|
|
import { QueuePaginator, getGlobalColor } from "../src/ui/index.mjs";
|
|
import { EmbedBuilder } from "@fluxerjs/core";
|
|
|
|
const PAGE_SIZE = 10;
|
|
const SESSION_MS = 30 * 1000;
|
|
|
|
/**
|
|
* @type {CommandBuilder}
|
|
* @description Command definition for the list (queue) command.
|
|
*/
|
|
export const command = new CommandBuilder()
|
|
.setName("list")
|
|
.setDescription("List the songs in the queue of your current voice channel.", "commands.list")
|
|
.setCategory("music")
|
|
.addAliases("queue", "q")
|
|
.addNumberOption(o =>
|
|
o.setName("page")
|
|
.setDescription("Page number to jump to.")
|
|
.setRequired(false)
|
|
);
|
|
|
|
/**
|
|
* Run handler for the list command.
|
|
* Displays the current queue with pagination, showing now-playing info and track list.
|
|
*
|
|
* @param {object} message - The command message wrapper.
|
|
* @param {object} data - Parsed command data containing the page option.
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function run(message, data) {
|
|
const p = await this.getPlayer(message);
|
|
if (!p) return;
|
|
|
|
const current = p.queue.getCurrent();
|
|
const totalTracks = p.queue.size();
|
|
|
|
if (!current && totalTracks === 0) {
|
|
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.list.empty", { prefix: this.handler.getPrefix(message.message?.guildId ?? message.channel?.guildId) }));
|
|
return message.reply({ embeds: [embed] });
|
|
}
|
|
|
|
const totalPages = totalTracks > 0
|
|
? Math.max(1, Math.ceil(totalTracks / PAGE_SIZE))
|
|
: 1;
|
|
|
|
const pageVal = data.get("page")?.value;
|
|
const startPage = Math.max(1, Math.min((!pageVal || isNaN(pageVal)) ? 1 : pageVal, totalPages));
|
|
|
|
const buildEmbed = (page) => {
|
|
const safePage = (isNaN(page) || page < 1) ? 1 : Math.min(Math.floor(page), totalPages);
|
|
const loopState = p.queue.songLoop ? "🔂 Song" : p.queue.loop ? "🔁 Queue" : "🛑 Off";
|
|
|
|
let desc = "";
|
|
|
|
const remaining = p.getQueueRemainingTime();
|
|
desc += `📋 **${totalTracks} track${totalTracks !== 1 ? "s" : ""} in queue** • ⏱️ \`${remaining}\`\n`;
|
|
|
|
if (current) {
|
|
const elapsed = p.getCurrentElapsedDuration();
|
|
const total = p.getCurrentDuration();
|
|
const link = current.spotifyUrl || current.url || "";
|
|
let title = current.title;
|
|
if (title.length > 50) title = title.slice(0, 47) + "...";
|
|
const titleFmt = link ? `[${title}](${link})` : title;
|
|
|
|
desc += "\n" + this.t(message, "responses.list.nowPlaying") + "\n";
|
|
desc += `${titleFmt} • \`${elapsed} / ${total}\`\n`;
|
|
}
|
|
|
|
desc += `\n`;
|
|
|
|
if (totalTracks === 0) {
|
|
desc += this.t(message, "responses.list.emptyInline");
|
|
} else {
|
|
const { items, start } = p.queue.getPage(safePage, PAGE_SIZE);
|
|
|
|
items.forEach((vid, i) => {
|
|
const index = String(start + i + 1).padStart(2, " ");
|
|
const dur = vid.duration ? p.getDuration(vid.duration) : "?:??";
|
|
const link = vid.spotifyUrl || vid.url || "";
|
|
let title = vid.title;
|
|
if (title.length > 45) title = title.slice(0, 42) + "...";
|
|
title = link ? `[${title}](${link})` : title;
|
|
const upNext = (start + i === 0) ? " ▶" : "";
|
|
desc += `\`${index}.\` ${title}${upNext} • \`${dur}\`\n`;
|
|
});
|
|
}
|
|
|
|
return new EmbedBuilder()
|
|
.setColor(getGlobalColor())
|
|
.setAuthor({ name: this.t(message, "responses.list.queueTitle") })
|
|
.setDescription(desc.trim())
|
|
.setFooter({ text: `Page ${safePage}/${totalPages} • ${loopState}` })
|
|
;
|
|
};
|
|
|
|
new QueuePaginator(message, this.messages, this.client)
|
|
.setTimeout(SESSION_MS)
|
|
.send(buildEmbed, totalPages, startPage)
|
|
.catch(() => {});
|
|
}
|