This commit is contained in:
NoLogicAlan committed 2026-05-04 16:19:02 +03:00
1 parent 6c3ae3d27c
commit 06bcc93ced
1 file changed
+48 -9
+48 -9
View File
@@ -622,6 +622,16 @@ class Remix {
logger.warn("[Gateway] GatewayError (12) received from Fluxer:", payload.d); logger.warn("[Gateway] GatewayError (12) received from Fluxer:", payload.d);
} }
if (payload?.op === GatewayOpcodes.Hello || payload?.op === 10) {
logger.player(`[Gateway] HELLO received (heartbeat ${payload.d?.heartbeat_interval ?? "unknown"}ms)`);
}
if (payload?.op === GatewayOpcodes.Reconnect || payload?.op === 7) {
logger.warn("[Gateway] RECONNECT requested by gateway.");
}
if (payload?.op === GatewayOpcodes.InvalidSession || payload?.op === 9) {
logger.warn("[Gateway] INVALID_SESSION received from gateway.");
}
if (payload?.op !== 0) return; if (payload?.op !== 0) return;
// READY payload contains an unavailable-guilds summary, but some // READY payload contains an unavailable-guilds summary, but some
@@ -630,6 +640,7 @@ class Remix {
// bot knows who is in voice immediately on reboot, before the // bot knows who is in voice immediately on reboot, before the
// individual GUILD_CREATE bursts complete. // individual GUILD_CREATE bursts complete.
if (payload.t === "READY") { if (payload.t === "READY") {
logger.player(`[Gateway] READY received (session ${payload.d?.session_id ?? "unknown"})`);
const readyGuilds = payload.d?.guilds; const readyGuilds = payload.d?.guilds;
if (Array.isArray(readyGuilds)) { if (Array.isArray(readyGuilds)) {
for (const g of readyGuilds) { for (const g of readyGuilds) {
@@ -641,12 +652,16 @@ class Remix {
if (!userId || !channelId) continue; if (!userId || !channelId) continue;
const isBot = state.member?.user?.bot ?? false; const isBot = state.member?.user?.bot ?? false;
const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers;
target.set(userId, { channelId, guildId: gId }); target.set(isBot ? getObservedVoiceBotKey(userId, gId) : userId, { channelId, guildId: gId });
} }
} }
} }
} }
if (payload.t === "RESUMED") {
logger.player("[Gateway] RESUMED received from gateway.");
}
if (payload.t === "GUILD_CREATE") { if (payload.t === "GUILD_CREATE") {
const d = payload.d; const d = payload.d;
const gId = d?.id; const gId = d?.id;
@@ -658,11 +673,15 @@ class Remix {
if (!userId || !channelId) continue; if (!userId || !channelId) continue;
const isBot = state.member?.user?.bot ?? false; const isBot = state.member?.user?.bot ?? false;
const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers;
target.set(userId, { channelId, guildId: gId }); target.set(isBot ? getObservedVoiceBotKey(userId, gId) : userId, { channelId, guildId: gId });
} }
} }
} }
if (payload.t === "VOICE_SERVER_UPDATE") {
logger.voiceState(`[Gateway] VOICE_SERVER_UPDATE guild=${payload.d?.guild_id ?? "dm"} endpoint=${payload.d?.endpoint ?? "unknown"}`);
}
if (payload.t === "VOICE_STATE_UPDATE") { if (payload.t === "VOICE_STATE_UPDATE") {
const d = payload.d; const d = payload.d;
const userId = d?.user_id; const userId = d?.user_id;
@@ -671,10 +690,11 @@ class Remix {
const isBot = d?.member?.user?.bot ?? false; const isBot = d?.member?.user?.bot ?? false;
if (!userId) return; if (!userId) return;
const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers;
const voiceKey = isBot ? getObservedVoiceBotKey(userId, guildId) : userId;
// WS path correctly deletes on channelId=null, // WS path correctly deletes on channelId=null,
// keeping observedVoice* from growing unbounded. // keeping observedVoice* from growing unbounded.
if (channelId) target.set(userId, { channelId, guildId }); if (channelId) target.set(voiceKey, { channelId, guildId });
else target.delete(userId); else if (voiceKey) target.delete(voiceKey);
} }
} catch (_) {} } catch (_) {}
}; };
@@ -739,6 +759,11 @@ class Remix {
// (channelId=null → delete) and in GuildDelete, so they don't grow unbounded. // (channelId=null → delete) and in GuildDelete, so they don't grow unbounded.
this.observedVoiceUsers = new Map(); this.observedVoiceUsers = new Map();
this.observedVoiceBots = new Map(); this.observedVoiceBots = new Map();
const getObservedVoiceBotKey = (userId, guildId) => {
const cleanUserId = String(userId ?? "").replace(/\D/g, "");
const cleanGuildId = String(guildId ?? "").replace(/\D/g, "");
return cleanUserId && cleanGuildId ? `${cleanGuildId}:${cleanUserId}` : cleanUserId || null;
};
// initialise announcement channel cache eagerly alongside other caches // initialise announcement channel cache eagerly alongside other caches
// so the hot path never needs a null-check allocation. // so the hot path never needs a null-check allocation.
this._announcementChannelCache = new Map(); this._announcementChannelCache = new Map();
@@ -787,7 +812,7 @@ class Remix {
if (!uid || !channelId) continue; if (!uid || !channelId) continue;
const isBot = val?.member?.user?.bot ?? false; const isBot = val?.member?.user?.bot ?? false;
const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers;
target.set(uid, { channelId, guildId }); target.set(isBot ? getObservedVoiceBotKey(uid, guildId) : uid, { channelId, guildId });
} }
} else { } else {
const entries = Array.isArray(voiceStatesRaw) const entries = Array.isArray(voiceStatesRaw)
@@ -801,7 +826,7 @@ class Remix {
const isBot = state?.member?.user?.bot ?? false; const isBot = state?.member?.user?.bot ?? false;
if (!channelId || !userId) continue; if (!channelId || !userId) continue;
const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot ? this.observedVoiceBots : this.observedVoiceUsers;
target.set(userId, { channelId, guildId: sgid }); target.set(isBot ? getObservedVoiceBotKey(userId, sgid) : userId, { channelId, guildId: sgid });
} }
} }
} }
@@ -941,13 +966,16 @@ class Remix {
// Always update/delete the voice maps so they never accumulate stale entries // Always update/delete the voice maps so they never accumulate stale entries
const target = isBot === true ? this.observedVoiceBots : this.observedVoiceUsers; const target = isBot === true ? this.observedVoiceBots : this.observedVoiceUsers;
const voiceKey = isBot === true ? getObservedVoiceBotKey(userId, guildId ?? prev?.guildId) : userId;
if (channelId) { if (channelId) {
target.set(userId, { channelId, guildId }); if (voiceKey) target.set(voiceKey, { channelId, guildId });
} else { } else {
// On leave, delete from BOTH maps — isBot can be null/inconsistent // On leave, delete from BOTH maps — isBot can be null/inconsistent
// between join and leave events, so the user may be in either map. // between join and leave events, so the user may be in either map.
this.observedVoiceUsers.delete(userId); this.observedVoiceUsers.delete(userId);
this.observedVoiceBots.delete(userId); if (voiceKey) this.observedVoiceBots.delete(voiceKey);
const fallbackBotKey = getObservedVoiceBotKey(userId, prev?.guildId);
if (fallbackBotKey && fallbackBotKey !== voiceKey) this.observedVoiceBots.delete(fallbackBotKey);
} }
const isBotUser = isBot === true && userId === client.user?.id; const isBotUser = isBot === true && userId === client.user?.id;
@@ -1157,12 +1185,23 @@ class Remix {
// _is247Enabled() checks the wrong channel against stay_247. // _is247Enabled() checks the wrong channel against stay_247.
const channelId = player._channelId ?? mapKey; const channelId = player._channelId ?? mapKey;
const cleanChanId = String(channelId).replace(/\D/g, ""); const cleanChanId = String(channelId).replace(/\D/g, "");
if (!cleanChanId) continue;
const cleanGuildId = String(guildId).replace(/\D/g, "");
const channelGuildId = String(
this.client?.channels?.cache?.get?.(channelId)?.guildId ??
this.client?.channels?.cache?.get?.(channelId)?.guild_id ??
""
).replace(/\D/g, "");
if (channelGuildId && channelGuildId !== cleanGuildId) {
logger.warn(`[AloneCheck] Skipping inconsistent player state channel=${channelId} playerGuild=${guildId} channelGuild=${channelGuildId}`);
continue;
}
// Skip if 247 is on or auto // Skip if 247 is on or auto
if (player._is247Enabled()) continue; if (player._is247Enabled()) continue;
// Read directly from observedVoiceUsers — bypass any cache issues // Read directly from observedVoiceUsers — bypass any cache issues
const cleanGuildId = String(guildId).replace(/\D/g, "");
let hasHuman = false; let hasHuman = false;
for (const [, info] of this.observedVoiceUsers) { for (const [, info] of this.observedVoiceUsers) {
const infoChannel = String(info.channelId ?? "").replace(/\D/g, ""); const infoChannel = String(info.channelId ?? "").replace(/\D/g, "");