mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
feat(stats): localize music stats, add shard and queue metrics, remove audio engine line
This commit is contained in:
1 parent
af23db1255
commit
d6c233c311
7 files changed
+114
-19
No files matched your search
+90
-19
@@ -10,6 +10,7 @@ import { Utils } from "../src/utils/Utils.mjs";
|
|||||||
import { EmbedBuilder } from "@fluxerjs/core";
|
import { EmbedBuilder } from "@fluxerjs/core";
|
||||||
import { getGlobalColor } from "../src/ui/index.mjs";
|
import { getGlobalColor } from "../src/ui/index.mjs";
|
||||||
import { logger } from "../src/core/Logger.mjs";
|
import { logger } from "../src/core/Logger.mjs";
|
||||||
|
import * as ShardingUtils from "../src/utils/ShardingUtils.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {CommandBuilder}
|
* @type {CommandBuilder}
|
||||||
@@ -226,18 +227,18 @@ async function withRateLimitRetry(fn, label = "send") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count players with active voice connections.
|
* Gather real-time music playback and player statistics.
|
||||||
|
* Deduplicates active players by instance and computes connected, playing,
|
||||||
|
* total queued tracks, and 24/7 radio sessions.
|
||||||
* @private
|
* @private
|
||||||
* @param {Map} playerMap - The player map from PlayerManager.
|
* @param {Map} playerMap - The player map from PlayerManager.
|
||||||
* @returns {number} Number of live connected players.
|
* @returns {{totalPlayers: number, playingCount: number, queuedTracks: number, radios247: number}}
|
||||||
*/
|
*/
|
||||||
function getLivePlayerCount(playerMap) {
|
function getMusicStats(playerMap) {
|
||||||
let live = 0;
|
const uniquePlayers = new Set();
|
||||||
|
if (playerMap) {
|
||||||
for (const [mapKey, player] of playerMap ?? []) {
|
for (const player of playerMap.values()) {
|
||||||
if (!player || player._destroyed || player.leaving) continue;
|
if (!player || player._destroyed || player.leaving || player._isJoining) continue;
|
||||||
if (player._isJoining) continue;
|
|
||||||
|
|
||||||
const conn = player.connection;
|
const conn = player.connection;
|
||||||
if (conn) {
|
if (conn) {
|
||||||
const room = conn.room;
|
const room = conn.room;
|
||||||
@@ -249,26 +250,71 @@ function getLivePlayerCount(playerMap) {
|
|||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
uniquePlayers.add(player);
|
||||||
live++;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return live;
|
let totalPlayers = uniquePlayers.size;
|
||||||
|
let playingCount = 0;
|
||||||
|
let queuedTracks = 0;
|
||||||
|
let radios247 = 0;
|
||||||
|
|
||||||
|
for (const player of uniquePlayers) {
|
||||||
|
const cur = player.queue?.getCurrent?.();
|
||||||
|
const isPlaying = !!cur && !player.paused;
|
||||||
|
if (isPlaying) playingCount++;
|
||||||
|
|
||||||
|
const qSize = (player.queue?.size?.() ?? 0) + (cur ? 1 : 0);
|
||||||
|
queuedTracks += qSize;
|
||||||
|
|
||||||
|
if (player._is247Enabled?.()) {
|
||||||
|
radios247++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalPlayers,
|
||||||
|
playingCount,
|
||||||
|
queuedTracks,
|
||||||
|
radios247,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate with a hardcoded fallback. Locale lookups that miss (custom or
|
* Resolve the current shard assignment string (e.g. "0/2" when sharded, or "0" in single-process mode).
|
||||||
* outdated locale files make translate() return the raw dot-notation key)
|
* @private
|
||||||
|
* @param {object} client - The bot client instance.
|
||||||
|
* @param {string|null} guildId - The guild ID where the command was invoked.
|
||||||
|
* @returns {string} Formatted shard info.
|
||||||
|
*/
|
||||||
|
function getShardInfo(client, guildId) {
|
||||||
|
try {
|
||||||
|
const isSharded = ShardingUtils.isShardedProcess();
|
||||||
|
const currentShard = ShardingUtils.shardIdForGuild(client, guildId);
|
||||||
|
if (isSharded) {
|
||||||
|
const totalShards = Number(process.env.FLUXER_SHARD_COUNT) || 1;
|
||||||
|
return totalShards > 1 ? `${currentShard}/${totalShards}` : `${currentShard}`;
|
||||||
|
}
|
||||||
|
return `${currentShard}`;
|
||||||
|
} catch (_) {
|
||||||
|
return "0";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translate with a hardcoded fallback and optional placeholders. Locale lookups
|
||||||
|
* that miss (custom or outdated locale files make translate() return the raw dot-notation key)
|
||||||
* render the readable fallback instead of an ugly key path in the embed.
|
* render the readable fallback instead of an ugly key path in the embed.
|
||||||
* @private
|
* @private
|
||||||
* @param {Function} t - Translation function.
|
* @param {Function} t - Translation function.
|
||||||
* @param {object} msg - The command message wrapper.
|
* @param {object} msg - The command message wrapper.
|
||||||
* @param {string} key - Locale key.
|
* @param {string} key - Locale key.
|
||||||
* @param {string} fallback - Label used when the key is missing.
|
* @param {string} fallback - Label used when the key is missing.
|
||||||
|
* @param {object} [vars={}] - Optional interpolation variables.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function tOr(t, msg, key, fallback) {
|
function tOr(t, msg, key, fallback, vars = {}) {
|
||||||
const value = t(msg, key);
|
const value = t(msg, key, vars);
|
||||||
return value === key ? fallback : value;
|
return value === key ? fallback : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +326,11 @@ function tOr(t, msg, key, fallback) {
|
|||||||
* @param {object} s - Statistics data object.
|
* @param {object} s - Statistics data object.
|
||||||
* @param {number} s.guildCount - Number of guilds.
|
* @param {number} s.guildCount - Number of guilds.
|
||||||
* @param {number} s.userCount - Number of users.
|
* @param {number} s.userCount - Number of users.
|
||||||
* @param {number} s.playerCount - Number of active players.
|
* @param {number} s.playerCount - Number of active connected players.
|
||||||
|
* @param {number} s.playingCount - Number of players actively streaming.
|
||||||
|
* @param {number} s.queuedTracks - Total tracks across all player queues.
|
||||||
|
* @param {number} s.radios247 - Number of active 24/7 radio sessions.
|
||||||
|
* @param {string} s.shard - Shard assignment string.
|
||||||
* @param {number} s.scrobbleCount - Total Last.fm scrobbles.
|
* @param {number} s.scrobbleCount - Total Last.fm scrobbles.
|
||||||
* @param {number} s.linkedUsers - Number of Last.fm linked users.
|
* @param {number} s.linkedUsers - Number of Last.fm linked users.
|
||||||
* @param {number} s.ping - Bot response ping in ms (REST reply round trip).
|
* @param {number} s.ping - Bot response ping in ms (REST reply round trip).
|
||||||
@@ -298,10 +348,19 @@ function buildEmbed(t, msg, s, pending = []) {
|
|||||||
const num = (v) => Utils.formatNumber(v);
|
const num = (v) => Utils.formatNumber(v);
|
||||||
const field = (key, value) => `\`${pending.includes(key) ? "..." : value}\``;
|
const field = (key, value) => `\`${pending.includes(key) ? "..." : value}\``;
|
||||||
|
|
||||||
|
const playerVal = s.playingCount > 0
|
||||||
|
? tOr(t, msg, "responses.stats.playersWithPlaying", `${num(s.playerCount)} (${num(s.playingCount)} playing)`, {
|
||||||
|
total: num(s.playerCount),
|
||||||
|
playing: num(s.playingCount),
|
||||||
|
})
|
||||||
|
: num(s.playerCount);
|
||||||
|
|
||||||
const description = [
|
const description = [
|
||||||
`${t(msg, "responses.stats.servers")} — ${field("guilds", num(s.guildCount))}`,
|
`${t(msg, "responses.stats.servers")} — ${field("guilds", num(s.guildCount))}`,
|
||||||
`${t(msg, "responses.stats.users")} — ${field("users", num(s.userCount))}`,
|
`${t(msg, "responses.stats.users")} — ${field("users", num(s.userCount))}`,
|
||||||
`${t(msg, "responses.stats.players")} — ${field("players", num(s.playerCount))}`,
|
`${t(msg, "responses.stats.players")} — ${field("players", playerVal)}`,
|
||||||
|
`${tOr(t, msg, "responses.stats.queuedTracks", "🎶 **Queued Tracks**")} — ${field("queuedTracks", num(s.queuedTracks))}`,
|
||||||
|
s.radios247 > 0 ? `${tOr(t, msg, "responses.stats.radios", "📻 **24/7 Radios**")} — ${field("radios", num(s.radios247))}` : null,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (s.lastfmEnabled) {
|
if (s.lastfmEnabled) {
|
||||||
@@ -314,6 +373,7 @@ function buildEmbed(t, msg, s, pending = []) {
|
|||||||
description.push(
|
description.push(
|
||||||
`${t(msg, "responses.stats.ping")} — ${field("ping", `${num(s.ping)}ms`)}`,
|
`${t(msg, "responses.stats.ping")} — ${field("ping", `${num(s.ping)}ms`)}`,
|
||||||
s.gatewayPing >= 0 ? `${tOr(t, msg, "responses.stats.gateway", GATEWAY_FALLBACK_LABEL)} — \`${num(s.gatewayPing)}ms\`` : null,
|
s.gatewayPing >= 0 ? `${tOr(t, msg, "responses.stats.gateway", GATEWAY_FALLBACK_LABEL)} — \`${num(s.gatewayPing)}ms\`` : null,
|
||||||
|
`${tOr(t, msg, "responses.stats.shard", "🧩 **Shard**")} — \`${s.shard}\``,
|
||||||
`${t(msg, "responses.stats.uptime")} — \`${s.uptime}\``,
|
`${t(msg, "responses.stats.uptime")} — \`${s.uptime}\``,
|
||||||
`${t(msg, "responses.stats.build")} — [\`${s.comHash}\`](${s.comLink})`,
|
`${t(msg, "responses.stats.build")} — [\`${s.comHash}\`](${s.comLink})`,
|
||||||
s.reason ? `${t(msg, "responses.stats.lastRestart")} — \`${s.reason}\`` : null,
|
s.reason ? `${t(msg, "responses.stats.lastRestart")} — \`${s.reason}\`` : null,
|
||||||
@@ -349,6 +409,8 @@ export async function run(message) {
|
|||||||
const t = (...a) => this.t(...a);
|
const t = (...a) => this.t(...a);
|
||||||
|
|
||||||
const totals = getTotals(this.client);
|
const totals = getTotals(this.client);
|
||||||
|
const music = getMusicStats(this.players?.playerMap);
|
||||||
|
const shard = getShardInfo(this.client, message.guildId ?? message.guild?.id);
|
||||||
|
|
||||||
scheduleBackgroundRefresh(this.client, lastfmEnabled ? lastfm : null);
|
scheduleBackgroundRefresh(this.client, lastfmEnabled ? lastfm : null);
|
||||||
|
|
||||||
@@ -363,7 +425,11 @@ export async function run(message) {
|
|||||||
const embedData = {
|
const embedData = {
|
||||||
guildCount: totals.guildCount,
|
guildCount: totals.guildCount,
|
||||||
userCount: totals.userCount,
|
userCount: totals.userCount,
|
||||||
playerCount: getLivePlayerCount(this.players.playerMap),
|
playerCount: music.totalPlayers,
|
||||||
|
playingCount: music.playingCount,
|
||||||
|
queuedTracks: music.queuedTracks,
|
||||||
|
radios247: music.radios247,
|
||||||
|
shard,
|
||||||
scrobbleCount: lastfmEnabled ? (cache.scrobbles ?? 0) : 0,
|
scrobbleCount: lastfmEnabled ? (cache.scrobbles ?? 0) : 0,
|
||||||
linkedUsers: lastfmEnabled ? (cache.linkedUsers ?? 0) : 0,
|
linkedUsers: lastfmEnabled ? (cache.linkedUsers ?? 0) : 0,
|
||||||
lastfmEnabled,
|
lastfmEnabled,
|
||||||
@@ -406,10 +472,15 @@ export async function run(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fresh = getTotals(this.client);
|
const fresh = getTotals(this.client);
|
||||||
|
const freshMusic = getMusicStats(this.players?.playerMap);
|
||||||
const fill = {
|
const fill = {
|
||||||
...embedData,
|
...embedData,
|
||||||
guildCount: fresh.guildCount,
|
guildCount: fresh.guildCount,
|
||||||
userCount: fresh.userCount,
|
userCount: fresh.userCount,
|
||||||
|
playerCount: freshMusic.totalPlayers,
|
||||||
|
playingCount: freshMusic.playingCount,
|
||||||
|
queuedTracks: freshMusic.queuedTracks,
|
||||||
|
radios247: freshMusic.radios247,
|
||||||
scrobbleCount: lastfmEnabled ? (cache.scrobbles ?? 0) : 0,
|
scrobbleCount: lastfmEnabled ? (cache.scrobbles ?? 0) : 0,
|
||||||
linkedUsers: lastfmEnabled ? (cache.linkedUsers ?? 0) : 0,
|
linkedUsers: lastfmEnabled ? (cache.linkedUsers ?? 0) : 0,
|
||||||
ping: lastPing ?? 0,
|
ping: lastPing ?? 0,
|
||||||
|
|||||||
@@ -614,10 +614,14 @@
|
|||||||
"servers": "📂 **الخوادم**",
|
"servers": "📂 **الخوادم**",
|
||||||
"users": "👥 **المستخدمون**",
|
"users": "👥 **المستخدمون**",
|
||||||
"players": "🎧 **المشغّلات**",
|
"players": "🎧 **المشغّلات**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} قيد التشغيل)",
|
||||||
|
"queuedTracks": "🎶 **المسارات في الانتظار**",
|
||||||
|
"radios": "📻 **محطات 24/7**",
|
||||||
"scrobbles": "🎵 **اسكروبلات**",
|
"scrobbles": "🎵 **اسكروبلات**",
|
||||||
"linkedUsers": "🔗 **حسابات Last.fm**",
|
"linkedUsers": "🔗 **حسابات Last.fm**",
|
||||||
"ping": "🏓 **البينغ**",
|
"ping": "🏓 **البينغ**",
|
||||||
"gateway": "🌐 **البوابة**",
|
"gateway": "🌐 **البوابة**",
|
||||||
|
"shard": "🧩 **الشارد (Shard)**",
|
||||||
"uptime": "⏱️ **وقت التشغيل**",
|
"uptime": "⏱️ **وقت التشغيل**",
|
||||||
"build": "🔧 **الإصدار**",
|
"build": "🔧 **الإصدار**",
|
||||||
"lastRestart": "🪛 **آخر إعادة تشغيل**",
|
"lastRestart": "🪛 **آخر إعادة تشغيل**",
|
||||||
|
|||||||
@@ -614,10 +614,14 @@
|
|||||||
"servers": "📂 **سێرڤەرەکان**",
|
"servers": "📂 **سێرڤەرەکان**",
|
||||||
"users": "👥 **بەکارهێنەران**",
|
"users": "👥 **بەکارهێنەران**",
|
||||||
"players": "🎧 **پەخشکەرەکان**",
|
"players": "🎧 **پەخشکەرەکان**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} لێدەدرێت)",
|
||||||
|
"queuedTracks": "🎶 **گۆرانییەکانی ڕیزبەند**",
|
||||||
|
"radios": "📻 **ڕادیۆکانی 24/7**",
|
||||||
"scrobbles": "🎵 **سکرۆبلەکان**",
|
"scrobbles": "🎵 **سکرۆبلەکان**",
|
||||||
"linkedUsers": "🔗 **هەژمارەکانی Last.fm**",
|
"linkedUsers": "🔗 **هەژمارەکانی Last.fm**",
|
||||||
"ping": "🏓 **پینگ**",
|
"ping": "🏓 **پینگ**",
|
||||||
"gateway": "🌐 **گەیتوەی**",
|
"gateway": "🌐 **گەیتوەی**",
|
||||||
|
"shard": "🧩 **شارد (Shard)**",
|
||||||
"uptime": "⏱️ **کاتی چالاک**",
|
"uptime": "⏱️ **کاتی چالاک**",
|
||||||
"build": "🔧 **بەرنامە**",
|
"build": "🔧 **بەرنامە**",
|
||||||
"lastRestart": "🪛 **دوایین دەستپێکردنەوە**",
|
"lastRestart": "🪛 **دوایین دەستپێکردنەوە**",
|
||||||
|
|||||||
@@ -614,10 +614,14 @@
|
|||||||
"servers": "📂 **Server**",
|
"servers": "📂 **Server**",
|
||||||
"users": "👥 **Benutzer**",
|
"users": "👥 **Benutzer**",
|
||||||
"players": "🎧 **Player**",
|
"players": "🎧 **Player**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} aktiv)",
|
||||||
|
"queuedTracks": "🎶 **Warteschlangen-Titel**",
|
||||||
|
"radios": "📻 **24/7-Radios**",
|
||||||
"scrobbles": "🎵 **Scrobbles**",
|
"scrobbles": "🎵 **Scrobbles**",
|
||||||
"linkedUsers": "🔗 **Verknüpfte Last.fm**",
|
"linkedUsers": "🔗 **Verknüpfte Last.fm**",
|
||||||
"ping": "🏓 **Ping**",
|
"ping": "🏓 **Ping**",
|
||||||
"gateway": "🌐 **Gateway**",
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"shard": "🧩 **Shard**",
|
||||||
"uptime": "⏱️ **Uptime**",
|
"uptime": "⏱️ **Uptime**",
|
||||||
"build": "🔧 **Build**",
|
"build": "🔧 **Build**",
|
||||||
"lastRestart": "🪛 **Letzter Neustart**",
|
"lastRestart": "🪛 **Letzter Neustart**",
|
||||||
|
|||||||
@@ -731,10 +731,14 @@
|
|||||||
"servers": "📂 **Servers**",
|
"servers": "📂 **Servers**",
|
||||||
"users": "👥 **Users**",
|
"users": "👥 **Users**",
|
||||||
"players": "🎧 **Players**",
|
"players": "🎧 **Players**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} playing)",
|
||||||
|
"queuedTracks": "🎶 **Queued Tracks**",
|
||||||
|
"radios": "📻 **24/7 Radios**",
|
||||||
"scrobbles": "🎵 **Scrobbles**",
|
"scrobbles": "🎵 **Scrobbles**",
|
||||||
"linkedUsers": "🔗 **Linked Last.fm**",
|
"linkedUsers": "🔗 **Linked Last.fm**",
|
||||||
"ping": "🏓 **Ping**",
|
"ping": "🏓 **Ping**",
|
||||||
"gateway": "🌐 **Gateway**",
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"shard": "🧩 **Shard**",
|
||||||
"uptime": "⏱️ **Uptime**",
|
"uptime": "⏱️ **Uptime**",
|
||||||
"build": "🔧 **Build**",
|
"build": "🔧 **Build**",
|
||||||
"lastRestart": "🪛 **Last restart**",
|
"lastRestart": "🪛 **Last restart**",
|
||||||
|
|||||||
@@ -614,10 +614,14 @@
|
|||||||
"servers": "📂 **Servidores**",
|
"servers": "📂 **Servidores**",
|
||||||
"users": "👥 **Usuários**",
|
"users": "👥 **Usuários**",
|
||||||
"players": "🎧 **Players**",
|
"players": "🎧 **Players**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} tocando)",
|
||||||
|
"queuedTracks": "🎶 **Músicas na Fila**",
|
||||||
|
"radios": "📻 **Rádios 24/7**",
|
||||||
"scrobbles": "🎵 **Scrobbles**",
|
"scrobbles": "🎵 **Scrobbles**",
|
||||||
"linkedUsers": "🔗 **Last.fm Vinculadas**",
|
"linkedUsers": "🔗 **Last.fm Vinculadas**",
|
||||||
"ping": "🏓 **Ping**",
|
"ping": "🏓 **Ping**",
|
||||||
"gateway": "🌐 **Gateway**",
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"shard": "🧩 **Shard**",
|
||||||
"uptime": "⏱️ **Tempo de Atividade**",
|
"uptime": "⏱️ **Tempo de Atividade**",
|
||||||
"build": "🔧 **Build**",
|
"build": "🔧 **Build**",
|
||||||
"lastRestart": "🪛 **Último Reinício**",
|
"lastRestart": "🪛 **Último Reinício**",
|
||||||
|
|||||||
@@ -720,10 +720,14 @@
|
|||||||
"servers": "📂 **Sunucular**",
|
"servers": "📂 **Sunucular**",
|
||||||
"users": "👥 **Kullanıcılar**",
|
"users": "👥 **Kullanıcılar**",
|
||||||
"players": "🎧 **Oynatıcılar**",
|
"players": "🎧 **Oynatıcılar**",
|
||||||
|
"playersWithPlaying": "{{total}} ({{playing}} çalıyor)",
|
||||||
|
"queuedTracks": "🎶 **Kuyruktaki Parçalar**",
|
||||||
|
"radios": "📻 **24/7 Radyolar**",
|
||||||
"scrobbles": "🎵 **Scrobble'lar**",
|
"scrobbles": "🎵 **Scrobble'lar**",
|
||||||
"linkedUsers": "🔗 **Bağlı Last.fm**",
|
"linkedUsers": "🔗 **Bağlı Last.fm**",
|
||||||
"ping": "🏓 **Ping**",
|
"ping": "🏓 **Ping**",
|
||||||
"gateway": "🌐 **Gateway**",
|
"gateway": "🌐 **Gateway**",
|
||||||
|
"shard": "🧩 **Shard**",
|
||||||
"uptime": "⏱️ **Çalışma Süresi**",
|
"uptime": "⏱️ **Çalışma Süresi**",
|
||||||
"build": "🔧 **Yapı**",
|
"build": "🔧 **Yapı**",
|
||||||
"lastRestart": "🪛 **Son yeniden başlatma**",
|
"lastRestart": "🪛 **Son yeniden başlatma**",
|
||||||
|
|||||||
Reference in new issue
Block a user