Files
fluxer/commands/servers.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

148 lines
4.4 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())
.setTitle(this.t(msg, "responses.servers.title", { count: 0 }))
.setDescription(this.t(msg, "responses.servers.noServers"))
;
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 line = `${i + 1}. **${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())
.setTitle(this.t(msg, "responses.servers.pageTitle", { count: guilds.length, page: pageIdx + 1, total: totalPages }))
.setDescription(pages[pageIdx])
.setFooter({
text: expired
? this.t(msg, "responses._common.controlsExpired")
: totalPages > 1
? this.t(msg, "responses._common.navigateHint")
: 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();
}