Files
fluxer/commands/servers.mjs
T
NoLogicAlan 3b9620012f feat: modernize UI, overhaul ErrorChannel telemetry, and achieve 100% 6-locale parity
- Core & Telemetry:
  * Overhaul ErrorChannel (config.errorLogChannel) to rich Pro Embeds with severity color coding (Error, Warn, Info).
  * Add structured crash reports featuring syntax-highlighted stack traces, uptime, and RSS memory telemetry.
  * Add log flood drop notifications and startup connection status announcement.
  * Support dynamic self-hosted Fluxer API base resolution (config.apiBase / config['fluxer.js'].api).
  * Wire ErrorChannel into the localization system with dynamic _t() translation and safe fallback.

- Localization & i18n:
  * Expand all 6 locale files (en, ar-SA, ckb, tr, de-DE, pt-BR) to 1,112 keys each.
  * Achieve 100% key parity and 0 variable mismatches across all supported languages.
  * Localize all embed titles, author badges, footers, and system responses.

- Commands & Modern UI:
  * Upgrade all commands (playback, queue, audio DSP, utility, lastfm, settings, owner) to the modern Pro UI embed design.
  * Add previous, replay, and skipto queue navigation commands with history tracking.
  * Replace raw unicode escapes with literal UTF-8 emojis.
  * Maintain clean codebase standards (zero single-line comments introduced, commands/stats.mjs strictly untouched).

- Architecture & Voice:
  * Enhance FluxerAudioBridge, VoiceStateRouting, and VoiceStateCache for reliable voice reconnects.
  * Refactor centralized database pooling and player lifecycle mixins.
2026-10-28 02:19:26 +03:00

150 lines
4.7 KiB
JavaScript

/**
* @module commands/servers
* @description Owner-only command to list all servers the bot is in with pagination.
*/
import { CommandBuilder } from "../src/commands/index.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";
/** @type {CommandBuilder} @description Command definition for the servers command (owner-only). */
export const command = new CommandBuilder()
.setName("servers")
.setDescription("Fetch a list of servers the bot is in")
.setRequirement(r => r.setOwnerOnly(true))
.setCategory("util");
/**
* @async
* Run handler for the servers command.
* Lists all guilds the bot is a member of, with paginated embed and reaction navigation.
* @param {object} msg - The command message wrapper.
* @returns {Promise<void>}
*/
export async function run(msg) {
const guilds = [...this.client.guilds.values()];
if (guilds.length === 0) {
const emptyEmbed = new EmbedBuilder()
.setColor(getGlobalColor())
.setAuthor({ name: this.t(msg, "responses.servers.serversAuthor") })
.setTitle(this.t(msg, "responses.servers.title", { count: 0 }))
.setDescription(this.t(msg, "responses.servers.noServers"))
.setFooter({ text: this.t(msg, "responses.servers.listComplete") });
return msg.reply({ embeds: [emptyEmbed] });
}
const MAX_DESC = 4096;
const pages = [];
let currentLines = [];
let currentLen = 0;
for (let i = 0; i < guilds.length; i++) {
const g = guilds[i];
let name = g.name || "unknown";
if (name.length > 40) name = name.slice(0, 37) + "...";
const num = String(i + 1).padStart(2, "0");
const line = `\`${num}.\` **${name}** \`(${g.id})\``;
const addedLen = line.length + (currentLines.length ? 1 : 0);
if (currentLen + addedLen > MAX_DESC - 20 && currentLines.length > 0) {
pages.push(currentLines.join("\n"));
currentLines = [];
currentLen = 0;
}
currentLines.push(line);
currentLen += addedLen;
}
if (currentLines.length) pages.push(currentLines.join("\n"));
const totalPages = pages.length;
let currentPage = 0;
/**
* @private
* Build the embed payload for a specific page of the server list.
* @param {number} pageIdx - Zero-based page index.
* @param {boolean} [expired=false] - Whether the reaction controls have expired.
* @returns {object} Embed payload for message reply/edit.
*/
const buildPageContent = (pageIdx, expired = false) => {
const embed = new EmbedBuilder()
.setColor(getGlobalColor())
.setAuthor({ name: this.t(msg, "responses.servers.serversAuthor") })
.setTitle(this.t(msg, "responses.servers.serversTitle"))
.setDescription(pages[pageIdx])
.setFooter({
text: expired
? this.t(msg, "responses._common.controlsExpired")
: totalPages > 1
? this.t(msg, "responses.servers.serversTelemetryFooter", { page: pageIdx + 1, total: totalPages })
: this.t(msg, "responses.servers.listComplete")
});
return { embeds: [embed] };
};
const replyMsg = await msg.reply(buildPageContent(0));
if (!replyMsg?.message) return;
if (totalPages <= 1) return;
const navEmojis = ["⬅️", "➡️"];
let unobserve = null;
let emojiTimeout = null;
for (const emoji of navEmojis) {
await replyMsg.message.react(emoji).catch(() => {});
}
/**
* @private
* Remove all navigation reactions from the reply message.
* @returns {Promise<void>}
*/
const clearReactions = async () => {
try {
await replyMsg.message.removeAllReactions();
} catch (e) {
for (const emoji of navEmojis) {
try {
await replyMsg.message.removeReaction(emoji);
} catch(e) { logger.warn("[Servers] Error:", e?.message); }
}
}
};
/**
* @private
* Reset the emoji removal timeout timer.
* @returns {void}
*/
const resetTimer = () => {
clearTimeout(emojiTimeout);
emojiTimeout = setTimeout(async () => {
if (unobserve) unobserve();
await clearReactions();
await replyMsg.edit(buildPageContent(currentPage, true)).catch(() => {});
}, EMOJI_REMOVE_TIMEOUT);
};
unobserve = replyMsg.onReaction(navEmojis, async (e) => {
resetTimer();
if (e.emoji_id === "⬅️") {
currentPage = currentPage > 0 ? currentPage - 1 : totalPages - 1;
} else if (e.emoji_id === "➡️") {
currentPage = currentPage < totalPages - 1 ? currentPage + 1 : 0;
}
await replyMsg.edit(buildPageContent(currentPage)).catch(() => {});
});
resetTimer();
}