From aaebd13f7072bd25fbe00809d18c2ece671e90f3 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:10:06 +0100 Subject: events: never join or move voice just to play TTS --- src/events/mod.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/events/mod.rs') diff --git a/src/events/mod.rs b/src/events/mod.rs index 5fb6a30..406490a 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -34,6 +34,22 @@ async fn play_tts_in_channel( channel_id: serenity::ChannelId, text: String, ) { + // Never join or move the bot from a voice-state event: that would let any + // user drag the bot (and its music/recording) into an arbitrary channel. + // Only speak if the bot is already in the channel where the event happened. + let Some(call) = voice_manager.get_call(guild_id) else { + return; + }; + let already_there = call + .lock() + .await + .current_channel() + .map(|current| current.0.get() == channel_id.get()) + .unwrap_or(false); + if !already_there { + return; + } + let audio_data = match tts.synthesize(&text).await { Ok(bytes) => bytes, Err(e) => { @@ -42,14 +58,6 @@ async fn play_tts_in_channel( } }; - let call = match voice_manager.connect(guild_id, channel_id).await { - Ok(c) => c, - Err(e) => { - warn!("Failed to connect to voice for TTS: {e}"); - return; - } - }; - let input = crate::tts::pcm_bytes_to_input(audio_data); let mut call_lock = call.lock().await; -- cgit v1.2.3