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).
101 lines
3.7 KiB
JavaScript
101 lines
3.7 KiB
JavaScript
/**
|
|
* @module commands/test
|
|
* @description Owner-only diagnostic command to display voice channel user counts.
|
|
*/
|
|
|
|
import { CommandBuilder } from "../src/commands/index.mjs";
|
|
import { EmbedBuilder } from "@fluxerjs/core";
|
|
import { getGlobalColor } from "../src/ui/index.mjs";
|
|
import { logger } from "../src/core/Logger.mjs";
|
|
|
|
/** @type {CommandBuilder} @description Command definition for the test command (owner-only). */
|
|
export const command = new CommandBuilder()
|
|
.setName("test")
|
|
.setDescription("Shows how many people are in each voice channel.")
|
|
.setCategory("util")
|
|
.setRequirement(r => r.setOwnerOnly(true));
|
|
|
|
/**
|
|
* @async
|
|
* Run handler for the test command.
|
|
* Iterates the voice state cache and reports user counts per voice channel.
|
|
* @param {object} msg - The command message wrapper.
|
|
* @param {object} data - Parsed command data (unused).
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function run(msg, data) {
|
|
const guild = msg.channel?.channel?.guild ?? msg.message?.guild;
|
|
if (!guild) {
|
|
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.test.notInServer"));
|
|
return msg.reply({ embeds: [embed] });
|
|
}
|
|
|
|
const channelCounts = new Map();
|
|
|
|
const cache = this.voiceCache ?? this.observedVoiceUsers;
|
|
if (cache) {
|
|
if (typeof cache.iterateHumanUsers === "function") {
|
|
for (const [, state] of cache.iterateHumanUsers()) {
|
|
if (state.guildId !== guild.id) continue;
|
|
channelCounts.set(state.channelId, (channelCounts.get(state.channelId) ?? 0) + 1);
|
|
}
|
|
} else {
|
|
for (const [, state] of cache) {
|
|
if (state.guildId !== guild.id) continue;
|
|
channelCounts.set(state.channelId, (channelCounts.get(state.channelId) ?? 0) + 1);
|
|
}
|
|
}
|
|
if (typeof cache.iterateBotUsers === "function") {
|
|
for (const [, state] of cache.iterateBotUsers()) {
|
|
if (state.guildId !== guild.id) continue;
|
|
channelCounts.set(state.channelId, (channelCounts.get(state.channelId) ?? 0) + 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (channelCounts.size === 0) {
|
|
const embed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(msg, "responses.test.noOneInVoice"));
|
|
return msg.reply({ embeds: [embed] });
|
|
}
|
|
|
|
/**
|
|
* @private
|
|
* Resolve a channel ID to a human-readable channel name.
|
|
* Tries cache, guild cache, then REST fetch as fallback.
|
|
* @param {string} channelId - The voice channel ID.
|
|
* @returns {Promise<string>} The channel name or a fallback string.
|
|
*/
|
|
const getChannelName = async (channelId) => {
|
|
const cached = this.client.channels.get(channelId);
|
|
if (cached?.name) return cached.name;
|
|
const guildCached = guild.channels?.get?.(channelId);
|
|
if (guildCached?.name) return guildCached.name;
|
|
if (guild.channels) {
|
|
const all = typeof guild.channels.values === "function"
|
|
? [...guild.channels.values()] : Object.values(guild.channels);
|
|
const found = all.find(c => (c.id ?? c.channel_id) === channelId);
|
|
if (found?.name) return found.name;
|
|
}
|
|
try {
|
|
const fetched = await this.client.channels.fetch(channelId);
|
|
if (fetched?.name) return fetched.name;
|
|
} catch(e) { logger.warn("[Test] Error:", e?.message); }
|
|
return `Unknown (${channelId})`;
|
|
};
|
|
|
|
let desc = "";
|
|
for (const [channelId, total] of channelCounts) {
|
|
const name = await getChannelName(channelId);
|
|
const entry = this.t(msg, "responses.test.channelEntry", { name, count: total });
|
|
if (desc.length + entry.length > 4080) break;
|
|
desc += entry;
|
|
}
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setColor(getGlobalColor())
|
|
.setTitle(this.t(msg, "responses.test.title"))
|
|
.setDescription(desc.trim().slice(0, 4096))
|
|
;
|
|
msg.reply({ embeds: [embed] }).catch(() => {});
|
|
}
|