mirror of
https://github.com/remix-bot/fluxer.git
synced 2026-11-24 06:01:44 -05:00
some fix
This commit is contained in:
1 parent
1227e897c9
commit
3f5c395986
4 files changed
+86
-10
No files matched your search
+24
-3
@@ -18,18 +18,39 @@ export function run(msg, data) {
|
|||||||
case "voice": {
|
case "voice": {
|
||||||
const servers = [...this.players.playerMap.entries()].map(([cid, s]) => {
|
const servers = [...this.players.playerMap.entries()].map(([cid, s]) => {
|
||||||
const channel = this.client.channels.get(cid);
|
const channel = this.client.channels.get(cid);
|
||||||
|
const conn = s.connection;
|
||||||
|
const room = conn?.room;
|
||||||
|
const roomState = room?.state ?? "no-room";
|
||||||
|
const hasMediaPlayer = !!s._mediaPlayer && !s._mediaPlayer?.destroyed;
|
||||||
return {
|
return {
|
||||||
name: channel?.name ?? "unknown",
|
name: channel?.name ?? "unknown",
|
||||||
id: channel?.id ?? cid,
|
id: channel?.id ?? cid,
|
||||||
status: s.connection?.state?.status ?? "unknown",
|
channelId: s._channelId ?? cid,
|
||||||
|
guildId: s._guildId ?? "unknown",
|
||||||
guildname: channel?.guild?.name ?? "unknown",
|
guildname: channel?.guild?.name ?? "unknown",
|
||||||
guildid: channel?.guildId ?? "unknown"
|
conn: conn ? "yes" : "null",
|
||||||
|
roomState,
|
||||||
|
mediaPlayer: hasMediaPlayer ? "alive" : (s._mediaPlayer?.destroyed ? "destroyed" : "none"),
|
||||||
|
destroyed: s._destroyed ?? false,
|
||||||
|
leaving: s.leaving ?? false,
|
||||||
|
joining: s._isJoining ?? false,
|
||||||
|
recovering: s._isRecovering ?? false,
|
||||||
|
paused: s._paused ?? false,
|
||||||
|
hasQueue: !!(s.queue?.getCurrent() || !s.queue?.isEmpty()),
|
||||||
|
home247: s._home247Channel ?? null,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
const pending = [...(this.players._pendingJoins ?? [])];
|
||||||
|
const summary = {
|
||||||
|
playerMapSize: this.players.playerMap.size,
|
||||||
|
livePlayers: servers.filter(s => s.conn === "yes" && !s.destroyed && !s.leaving).length,
|
||||||
|
pendingJoins: pending.length,
|
||||||
|
pendingChannels: pending,
|
||||||
|
};
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(getGlobalColor())
|
.setColor(getGlobalColor())
|
||||||
.setTitle(this.t(msg, "responses.debug.voiceTitle"))
|
.setTitle(this.t(msg, "responses.debug.voiceTitle"))
|
||||||
.setDescription("```json\n" + JSON.stringify(servers, null, 2) + "\n```")
|
.setDescription("```json\n" + JSON.stringify({ summary, servers }, null, 2) + "\n```")
|
||||||
;
|
;
|
||||||
msg.reply({ embeds: [embed] });
|
msg.reply({ embeds: [embed] });
|
||||||
break;
|
break;
|
||||||
|
|||||||
+8
-1
@@ -89,16 +89,23 @@ export async function joinChannel(message, cid, cb = () => {}, ecb = () => {}) {
|
|||||||
message.channel.send({ embeds: [embed] });
|
message.channel.send({ embeds: [embed] });
|
||||||
});
|
});
|
||||||
|
|
||||||
this.players.playerMap.set(cleanChannelId, p);
|
// Mark as pending so concurrent commands see the channel is taken,
|
||||||
|
// but don't add to playerMap until join() succeeds to avoid phantom
|
||||||
|
// entries inflating the player count.
|
||||||
|
this.players._pendingJoins.add(cleanChannelId);
|
||||||
|
|
||||||
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joining"));
|
const joiningEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joining"));
|
||||||
const statusMsg = await message.reply({ embeds: [joiningEmbed] });
|
const statusMsg = await message.reply({ embeds: [joiningEmbed] });
|
||||||
try {
|
try {
|
||||||
await p.join(cleanChannelId);
|
await p.join(cleanChannelId);
|
||||||
|
// Only add to playerMap after join succeeds
|
||||||
|
this.players.playerMap.set(cleanChannelId, p);
|
||||||
|
this.players._pendingJoins.delete(cleanChannelId);
|
||||||
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joined", { channel: cid }));
|
const okEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joined", { channel: cid }));
|
||||||
await statusMsg.edit({ embeds: [okEmbed] });
|
await statusMsg.edit({ embeds: [okEmbed] });
|
||||||
cb(p);
|
cb(p);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
this.players._pendingJoins.delete(cleanChannelId);
|
||||||
this.players.playerMap.delete(cleanChannelId);
|
this.players.playerMap.delete(cleanChannelId);
|
||||||
p.destroy();
|
p.destroy();
|
||||||
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joinFailed", { error: e.message }));
|
const errEmbed = new EmbedBuilder().setColor(getGlobalColor()).setDescription(this.t(message, "responses.join.joinFailed", { error: e.message }));
|
||||||
|
|||||||
+31
-5
@@ -73,18 +73,44 @@ function getUserCount(client) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLivePlayerCount(playerMap) {
|
function getLivePlayerCount(playerMap) {
|
||||||
const liveChannels = new Set();
|
let live = 0;
|
||||||
|
const seenGuilds = new Set();
|
||||||
|
|
||||||
for (const [mapKey, player] of playerMap ?? []) {
|
for (const [mapKey, player] of playerMap ?? []) {
|
||||||
|
// Skip null / destroyed / leaving entries
|
||||||
if (!player || player._destroyed || player.leaving) continue;
|
if (!player || player._destroyed || player.leaving) continue;
|
||||||
|
|
||||||
const channelId = String(player._channelId ?? mapKey ?? "").replace(/\D/g, "");
|
// Skip players still in the join() phase — they don't have a voice
|
||||||
if (!channelId) continue;
|
// connection yet and may fail to connect.
|
||||||
|
if (player._isJoining) continue;
|
||||||
|
|
||||||
liveChannels.add(channelId);
|
// A player is only "live" if it has an actual voice connection.
|
||||||
|
// Stale entries (gateway disconnect, LiveKit drop) that haven't been
|
||||||
|
// cleaned up yet will have connection = null or a dead room state.
|
||||||
|
const conn = player.connection;
|
||||||
|
if (conn) {
|
||||||
|
const room = conn.room;
|
||||||
|
if (room) {
|
||||||
|
const state = room.state;
|
||||||
|
// Explicitly dead states → skip
|
||||||
|
if (state === "disconnected" || state === "failed" || state === 0) continue;
|
||||||
|
// undefined = connected on some LiveKit builds (no persistent state prop)
|
||||||
|
// "connected" = explicitly connected
|
||||||
|
}
|
||||||
|
// conn exists but no room → still a valid LiveKit connection reference
|
||||||
|
} else {
|
||||||
|
// No connection at all → not live
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return liveChannels.size;
|
live++;
|
||||||
|
|
||||||
|
// Also track unique guilds so we can report server count
|
||||||
|
const guildId = String(player._guildId ?? "").replace(/\D/g, "");
|
||||||
|
if (guildId) seenGuilds.add(guildId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return live;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Embed builder ─────────────────────────────────────────────────────────────
|
// ── Embed builder ─────────────────────────────────────────────────────────────
|
||||||
|
|||||||
+23
-1
@@ -84,6 +84,9 @@ export class PlayerManager {
|
|||||||
/** @type {Map<string, Player>} */
|
/** @type {Map<string, Player>} */
|
||||||
playerMap = new Map();
|
playerMap = new Map();
|
||||||
|
|
||||||
|
/** @type {Set<string>} Channel IDs currently being joined (not yet in playerMap) */
|
||||||
|
_pendingJoins = new Set();
|
||||||
|
|
||||||
/** @type {Object} */
|
/** @type {Object} */
|
||||||
config;
|
config;
|
||||||
|
|
||||||
@@ -459,6 +462,10 @@ export class PlayerManager {
|
|||||||
player.textChannel = message.channel;
|
player.textChannel = message.channel;
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
// Also check if a join is in-progress for this channel
|
||||||
|
if (this._pendingJoins.has(cleanUserChannelId)) {
|
||||||
|
return null; // A player is being created — caller should retry
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const serverPlayers = cleanGuildId
|
const serverPlayers = cleanGuildId
|
||||||
@@ -684,6 +691,10 @@ export class PlayerManager {
|
|||||||
cb(existing);
|
cb(existing);
|
||||||
return message.reply(mkEmbed(this._t(message, "responses.join.alreadyJoined", { channel: cid })));
|
return message.reply(mkEmbed(this._t(message, "responses.join.alreadyJoined", { channel: cid })));
|
||||||
}
|
}
|
||||||
|
// Also block if a join is already in-progress for this channel
|
||||||
|
if (this._pendingJoins.has(cleanChannelId)) {
|
||||||
|
return message.reply(mkEmbed(this._t(message, "responses.join.joining")));
|
||||||
|
}
|
||||||
|
|
||||||
const player = new Player(this.config.token, {
|
const player = new Player(this.config.token, {
|
||||||
...this.playerConfig,
|
...this.playerConfig,
|
||||||
@@ -770,12 +781,21 @@ export class PlayerManager {
|
|||||||
if (typeof ch?.send === "function") ch.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
|
if (typeof ch?.send === "function") ch.send(typeof m === "object" && Array.isArray(m.embeds) ? m : mkEmbed(m));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.playerMap.set(cleanChannelId, player);
|
// Mark as "pending join" so concurrent getPlayer() / checkVoiceChannels()
|
||||||
|
// calls can see a player is being created for this channel, but stats
|
||||||
|
// won't count it until the join actually succeeds.
|
||||||
|
this._pendingJoins.add(cleanChannelId);
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining")));
|
const statusMsg = await message.reply(mkEmbed(this._t(message, "responses.join.joining")));
|
||||||
try {
|
try {
|
||||||
await player.join(cid);
|
await player.join(cid);
|
||||||
|
|
||||||
|
// Only add to playerMap after join succeeds — this prevents phantom
|
||||||
|
// entries from inflating the player count.
|
||||||
|
this.playerMap.set(cleanChannelId, player);
|
||||||
|
this._pendingJoins.delete(cleanChannelId);
|
||||||
|
|
||||||
await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joined", { channel: cid })));
|
await statusMsg.edit(mkEmbed(this._t(message, "responses.join.joined", { channel: cid })));
|
||||||
|
|
||||||
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
const guildId = cleanId(channel.guildId ?? getMessageGuildId(message));
|
||||||
@@ -789,6 +809,8 @@ export class PlayerManager {
|
|||||||
|
|
||||||
cb(player);
|
cb(player);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
this._pendingJoins.delete(cleanChannelId);
|
||||||
|
|
||||||
const errCode = sanitizeJoinError(err);
|
const errCode = sanitizeJoinError(err);
|
||||||
let errorMsg;
|
let errorMsg;
|
||||||
if (errCode === "PERMISSION") {
|
if (errCode === "PERMISSION") {
|
||||||
|
|||||||
Reference in new issue
Block a user