Files
fluxer/commands/list.mjs
T
NoLogicAlan 092268281a refactor: centralize shared utilities, fix voice intent, and improve error visibility
- extract `cleanId()` to `Utils.mjs` and remove 97+ inline `String(x).replace(/\D/g, "")` duplicates

- add `VoiceStateResolver.mjs` with `iterateVoiceStates`, `hasHumansInChannel`, `getChannelsWithHumans` — eliminates 12+ duplicated voice-state-iteration blocks across `Player`, `PlayerManager`, `GatewayHandler`, `Dashboard`

- add `UI.mjs` for shared color, emoji, and timeout constants

- move `parseInlineProvider` to `providers.mjs`, `getMessageGuildId` to `MessageHandler.mjs`

- fix `VoiceStateCache.removeGuild` and `TrackOptionsManager` cache deletion mutating Maps during iteration

- fix `checkVoiceChannels` now async returning `{channelId, alreadyInVoice, hasHumans}` — all callers updated

- fix `FluxerRevoice` global `console.log` monkey-patch replaced with scoped `withSuppressedLiveKitLogs(fn)`

- fix `Player._get247Mode()` settings resolution chain

- fix `runnables.mjs` validators were no-ops

- promote `Player` magic numbers to named static constants

- replace all silent `catch (_) {}` with `logger.warn()` throughout

- remove unused deps: `express`, `genius-lyrics`, `ws`

- add `@file` JSDoc headers to all modules
2026-06-15 16:56:10 +03:00

102 lines
3.6 KiB
JavaScript

/**
* @file list.mjs — Display the current song queue with pagination
* @module commands.list
*/
import { CommandBuilder } from "../src/CommandHandler.mjs";
import { QueuePaginator, getGlobalColor } from "../src/MessageHandler.mjs";
import { EmbedBuilder } from "@fluxerjs/core";
const PAGE_SIZE = 10;
const SESSION_MS = 30 * 1000;
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)
);
/**
* Execute the list command.
* @param {import("../src/MessageHandler.mjs").Message} message - The incoming message
* @param {Map<string, {value: *}>>} data - Slash-command options map
* @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(() => {});
}