From a557c37d086311976cbbfb4f912479bf51d9c6d4 Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Mon, 4 May 2026 16:31:20 +0300 Subject: [PATCH] cleaning --- commands/stats.mjs | 17 ++++++++++++++++- src/PlayerManager.mjs | 20 ++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/commands/stats.mjs b/commands/stats.mjs index e9355bd..ec4ccce 100644 --- a/commands/stats.mjs +++ b/commands/stats.mjs @@ -72,6 +72,21 @@ function getUserCount(client) { return inflightPromise; } +function getLivePlayerCount(playerMap) { + const liveChannels = new Set(); + + for (const [mapKey, player] of playerMap ?? []) { + if (!player || player._destroyed || player.leaving) continue; + + const channelId = String(player._channelId ?? mapKey ?? "").replace(/\D/g, ""); + if (!channelId) continue; + + liveChannels.add(channelId); + } + + return liveChannels.size; +} + // ── Embed builder ───────────────────────────────────────────────────────────── function buildEmbed({ guildCount, userCount, playerCount, ping, uptime, comHash, comLink, reason, footer, loading }) { @@ -106,7 +121,7 @@ function buildEmbed({ guildCount, userCount, playerCount, ping, uptime, comHash, export async function run(message) { const shared = { guildCount: this.client.guilds.cache.size, - playerCount: this.players.playerMap.size, + playerCount: getLivePlayerCount(this.players.playerMap), uptime: Utils.prettifyMS(Math.round(process.uptime()) * 1000), comHash: this.comHash, comLink: this.comLink, diff --git a/src/PlayerManager.mjs b/src/PlayerManager.mjs index e2ae987..75b17c1 100644 --- a/src/PlayerManager.mjs +++ b/src/PlayerManager.mjs @@ -114,9 +114,13 @@ export class PlayerManager { const cleanServerId = serverId ? String(serverId).replace(/\D/g, "") : null; const userChannelId = this.checkVoiceChannels(message); + const cleanUserChannelId = userChannelId ? String(userChannelId).replace(/\D/g, "") : null; - if (userChannelId) { - const player = this.playerMap.get(userChannelId); + if (cleanUserChannelId) { + const player = this.playerMap.get(cleanUserChannelId) + ?? [...this.playerMap.values()].find(p => + String(p?._channelId ?? "").replace(/\D/g, "") === cleanUserChannelId + ); if (player) { player.textChannel = message.channel; return player; @@ -124,11 +128,9 @@ export class PlayerManager { } const serverPlayers = cleanServerId - ? [...this.playerMap.entries()].filter(([chId]) => { - const ch = this.commands.client?.channels?.get(chId) ?? - this.commands.client?.channels?.cache?.get(chId); - const chGuild = String(ch?.guildId ?? ch?.server_id ?? ch?.serverId ?? "").replace(/\D/g, ""); - return chGuild === cleanServerId; + ? [...this.playerMap.entries()].filter(([, player]) => { + const playerGuildId = String(player?._guildId ?? "").replace(/\D/g, ""); + return playerGuildId === cleanServerId; }) : []; @@ -147,7 +149,9 @@ export class PlayerManager { return null; } - const match = serverPlayers.find(([chId]) => chId === userChannelId); + const match = serverPlayers.find(([, player]) => + String(player?._channelId ?? "").replace(/\D/g, "") === cleanUserChannelId + ); if (match) { match[1].textChannel = message.channel; return match[1];