mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
- 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.
109 lines
4.1 KiB
JavaScript
109 lines
4.1 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())
|
|
.setAuthor({ name: this.t(msg, "responses.test.author") })
|
|
.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())
|
|
.setAuthor({ name: this.t(msg, "responses.test.author") })
|
|
.setDescription(this.t(msg, "responses.test.noOneInVoice"))
|
|
.setFooter({ text: this.t(msg, "responses.test.footerZero") });
|
|
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())
|
|
.setAuthor({ name: this.t(msg, "responses.test.author") })
|
|
.setTitle(this.t(msg, "responses.test.title"))
|
|
.setDescription(desc.trim().slice(0, 4096))
|
|
.setFooter({ text: this.t(msg, "responses.test.footerCount", { count: channelCounts.size }) });
|
|
msg.reply({ embeds: [embed] }).catch(() => {});
|
|
}
|