Fix: Voice claim system - radio stops when soundboard plays

Plugins now claim voice per guild via claimVoice(). When soundboard
plays a sound, radio's cleanup runs automatically (kills ffmpeg,
broadcasts SSE stop event). Fixes stale "now playing" UI on tab switch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Daniel 2026-03-06 10:21:11 +01:00
parent e0635b30ef
commit 1e4ccfb1f1
3 changed files with 30 additions and 0 deletions

View file

@ -7,6 +7,7 @@ import {
import type { VoiceBasedChannel } from 'discord.js';
import { ChannelType } from 'discord.js';
import type { Plugin, PluginContext } from '../../core/plugin.js';
import { claimVoice, releaseVoice } from '../../core/plugin.js';
import { sseBroadcast } from '../../core/sse.js';
import { getState, setState } from '../../core/persistence.js';
import {
@ -68,6 +69,7 @@ function stopStream(guildId: string): void {
try { state.player.stop(true); } catch {}
try { getVoiceConnection(guildId)?.destroy(); } catch {}
guildRadioState.delete(guildId);
releaseVoice(guildId, 'radio');
broadcastState(guildId);
console.log(`[Radio] Stopped stream in guild ${guildId}`);
}
@ -148,6 +150,9 @@ async function startStream(
stopStream(guildId);
});
// Claim voice for this guild (stops other plugins like soundboard)
claimVoice(guildId, 'radio', () => stopStream(guildId));
// State tracken
const channelName = 'name' in channel ? (channel as any).name : voiceChannelId;
guildRadioState.set(guildId, {