From c727b445a4d62fd718f3851241532eb8e564769c Mon Sep 17 00:00:00 2001 From: vibe-bot Date: Mon, 11 Aug 2025 00:14:07 +0200 Subject: [PATCH] =?UTF-8?q?fix(exit-logic):=20Exit=20nur=20bei=20Disconnec?= =?UTF-8?q?t=20(after=20is=20null),=20bei=20Kanalwechsel=20unterdr=C3=BCck?= =?UTF-8?q?en;=20Lifecycle-Listener=20nur=20einmal=20registrieren=20und=20?= =?UTF-8?q?MaxListeners=20erh=C3=B6hen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/index.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/index.ts b/server/src/index.ts index cb43e2d..e962928 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -397,6 +397,9 @@ async function ensureConnectionReady(connection: VoiceConnection, channelId: str function attachVoiceLifecycle(state: GuildAudioState, guild: any) { const { connection } = state; + // Mehrfach-Registrierung verhindern + if ((connection as any).__lifecycleAttached) return; + try { (connection as any).setMaxListeners?.(0); } catch {} connection.on('stateChange', async (oldS: any, newS: any) => { console.log(`${new Date().toISOString()} | VoiceConnection: ${oldS.status} -> ${newS.status}`); try { @@ -434,6 +437,7 @@ function attachVoiceLifecycle(state: GuildAudioState, guild: any) { console.error(`${new Date().toISOString()} | Voice lifecycle handler error`, e); } }); + (connection as any).__lifecycleAttached = true; } client.once(Events.ClientReady, () => { @@ -471,9 +475,9 @@ client.on(Events.VoiceStateUpdate, async (oldState: VoiceState, newState: VoiceS } } } - // Exit: Nutzer verlässt einen Channel (vollständig oder wechselt zu anderem) - if (before && (!after || after !== before)) { - console.log(`${new Date().toISOString()} | Exit condition met for user=${userId} before=${before} after=${after ?? '-'}`); + // Exit: Nur wenn Nutzer wirklich auflegt (after ist leer). Bei Wechsel KEIN Exit-Sound. + if (before && !after) { + console.log(`${new Date().toISOString()} | Exit condition met (disconnect) for user=${userId} before=${before}`); const mapping = persistedState.exitSounds ?? {}; const file = mapping[userId]; if (file) { @@ -486,6 +490,9 @@ client.on(Events.VoiceStateUpdate, async (oldState: VoiceState, newState: VoiceS } catch (e) { console.warn('Exit play error', e); } } } + } else if (before && after && before !== after) { + // Kanalwechsel: Exit-Sound unterdrücken + console.log(`${new Date().toISOString()} | Exit suppressed (move) for user=${userId} before=${before} after=${after}`); } } catch (e) { console.warn('VoiceStateUpdate entrance/exit handling error', e);