aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-04 01:10:06 +0100
committersalmonik <salmonik@tuta.io>2026-11-04 01:10:23 +0100
commitaaebd13f7072bd25fbe00809d18c2ece671e90f3 (patch)
tree7b27455f8afba5f089e768c3ad213174e568a842
parentrecording: keep one buffer per guild (diff)
downloadsenator-sperma-aaebd13f7072bd25fbe00809d18c2ece671e90f3.tar.gz
senator-sperma-aaebd13f7072bd25fbe00809d18c2ece671e90f3.zip
events: never join or move voice just to play TTS
-rw-r--r--src/events/mod.rs24
1 files changed, 16 insertions, 8 deletions
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(
34 channel_id: serenity::ChannelId, 34 channel_id: serenity::ChannelId,
35 text: String, 35 text: String,
36) { 36) {
37 // Never join or move the bot from a voice-state event: that would let any
38 // user drag the bot (and its music/recording) into an arbitrary channel.
39 // Only speak if the bot is already in the channel where the event happened.
40 let Some(call) = voice_manager.get_call(guild_id) else {
41 return;
42 };
43 let already_there = call
44 .lock()
45 .await
46 .current_channel()
47 .map(|current| current.0.get() == channel_id.get())
48 .unwrap_or(false);
49 if !already_there {
50 return;
51 }
52
37 let audio_data = match tts.synthesize(&text).await { 53 let audio_data = match tts.synthesize(&text).await {
38 Ok(bytes) => bytes, 54 Ok(bytes) => bytes,
39 Err(e) => { 55 Err(e) => {
@@ -42,14 +58,6 @@ async fn play_tts_in_channel(
42 } 58 }
43 }; 59 };
44 60
45 let call = match voice_manager.connect(guild_id, channel_id).await {
46 Ok(c) => c,
47 Err(e) => {
48 warn!("Failed to connect to voice for TTS: {e}");
49 return;
50 }
51 };
52
53 let input = crate::tts::pcm_bytes_to_input(audio_data); 61 let input = crate::tts::pcm_bytes_to_input(audio_data);
54 62
55 let mut call_lock = call.lock().await; 63 let mut call_lock = call.lock().await;