diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-21 17:10:23 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-21 17:10:23 +0200 |
| commit | 2e614665e0c62fe572b5af53a2a6be1116d66720 (patch) | |
| tree | dbb48ad5d665a3f3d8c793db30a523264f17bcde /cogs/vclogs.py | |
| parent | fix naming not resolving things like %20 (diff) | |
| parent | Fix voice reconnect race: reuse VoiceClient instead of destroying it (diff) | |
| download | senator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.tar.gz senator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.zip | |
Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5) from dev into main
Reviewed-on: https://codeberg.org/salmonik/senator-sperma/pulls/5
Diffstat (limited to 'cogs/vclogs.py')
| -rw-r--r-- | cogs/vclogs.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index e5ca202..35826d4 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -116,7 +116,7 @@ class VcLogs(commands.Cog): | |||
| 116 | 116 | ||
| 117 | voice_mgr = self.get_voice_manager() | 117 | voice_mgr = self.get_voice_manager() |
| 118 | temp_dir = get_temp_dir() | 118 | temp_dir = get_temp_dir() |
| 119 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") | 119 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3") |
| 120 | tts = gTTS(text=text, lang='pl') | 120 | tts = gTTS(text=text, lang='pl') |
| 121 | logger.info("saving file") | 121 | logger.info("saving file") |
| 122 | 122 | ||
| @@ -129,6 +129,16 @@ class VcLogs(commands.Cog): | |||
| 129 | is_connected = voice_status[1] if voice_status else False | 129 | is_connected = voice_status[1] if voice_status else False |
| 130 | is_playing = voice_status[2] if voice_status else False | 130 | is_playing = voice_status[2] if voice_status else False |
| 131 | 131 | ||
| 132 | if is_connected: | ||
| 133 | from cogs.voice import is_voice_client_alive | ||
| 134 | if not is_voice_client_alive(voice_client, channel.guild): | ||
| 135 | logger.warning("Stale voice client in play_tts, reconnecting") | ||
| 136 | try: | ||
| 137 | await voice_client.disconnect() | ||
| 138 | except Exception: | ||
| 139 | pass | ||
| 140 | is_connected = False | ||
| 141 | |||
| 132 | if not is_connected: | 142 | if not is_connected: |
| 133 | voice_client = await voice_mgr.join_channel(channel) | 143 | voice_client = await voice_mgr.join_channel(channel) |
| 134 | voice_status = await voice_mgr.get_voice_status(channel.guild) | 144 | voice_status = await voice_mgr.get_voice_status(channel.guild) |
| @@ -150,12 +160,7 @@ class VcLogs(commands.Cog): | |||
| 150 | 160 | ||
| 151 | logger.info("preparing to play audio") | 161 | logger.info("preparing to play audio") |
| 152 | audio_source = discord.FFmpegPCMAudio(tts_file) | 162 | audio_source = discord.FFmpegPCMAudio(tts_file) |
| 153 | if volume != 1.0: | 163 | await voice_mgr.play_source(channel, audio_source, volume=volume) |
| 154 | audio_source = discord.PCMVolumeTransformer(audio_source) | ||
| 155 | audio_source.volume = volume | ||
| 156 | voice_client.play(audio_source) | ||
| 157 | while voice_client.is_playing(): | ||
| 158 | await asyncio.sleep(0.1) | ||
| 159 | except Exception as e: | 164 | except Exception as e: |
| 160 | logger.error(f"TTS playback error: {e}") | 165 | logger.error(f"TTS playback error: {e}") |
| 161 | finally: | 166 | finally: |
