diff options
| author | salmonik <raisersoft@proton.me> | 2026-05-20 15:40:18 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-05-20 15:40:18 +0200 |
| commit | 4663f260b55de0975661fda1c00f60d2ca6e4506 (patch) | |
| tree | b649850859595542f8e7916a5513e0840e911318 /cogs/cron.py | |
| parent | Fix TTS and AI voice playback bugs (diff) | |
| download | senator-sperma-4663f260b55de0975661fda1c00f60d2ca6e4506.tar.gz senator-sperma-4663f260b55de0975661fda1c00f60d2ca6e4506.zip | |
Clean up consumers: replace polling with VoiceManager.play_source()
- cron.py: replace while-is_playing polling with VoiceManager.play_source()
- vclogs.py: replace while-is_playing polling with VoiceManager.play_source()
- stop.py: use VoiceManager.disconnect() instead of raw voice_client
- join.py: use VoiceManager.connect() instead of raw channel.connect()
- voice.py: add back join_by_channel_id() convenience method
- Tests: update for new VoiceManager method names and signatures
Diffstat (limited to '')
| -rw-r--r-- | cogs/cron.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/cogs/cron.py b/cogs/cron.py index aad43d2..ee88085 100644 --- a/cogs/cron.py +++ b/cogs/cron.py | |||
| @@ -145,29 +145,23 @@ class Cron(commands.Cog): | |||
| 145 | 145 | ||
| 146 | if isinstance(channel, discord.VoiceChannel): | 146 | if isinstance(channel, discord.VoiceChannel): |
| 147 | voice_mgr = get_voice_manager(self.bot) | 147 | voice_mgr = get_voice_manager(self.bot) |
| 148 | voice_client = await voice_mgr.join_channel(channel) | ||
| 149 | if not voice_client: | ||
| 150 | if channel.guild.system_channel: | ||
| 151 | await channel.guild.system_channel.send( | ||
| 152 | "Nie udano się połączyć z kanałem głosowym" | ||
| 153 | ) | ||
| 154 | return | ||
| 155 | 148 | ||
| 156 | try: | 149 | try: |
| 157 | audio_source = discord.FFmpegPCMAudio(audio_url) | 150 | audio_source = discord.FFmpegPCMAudio(audio_url) |
| 158 | voice_client.play(audio_source) | 151 | success = await voice_mgr.play_source(channel, audio_source) |
| 159 | 152 | ||
| 160 | while voice_client.is_playing(): | 153 | if success: |
| 161 | await asyncio.sleep(1) | 154 | logger.info(f"Finished playing audio: {audio_url}") |
| 155 | else: | ||
| 156 | raise Exception("Playback failed") | ||
| 162 | 157 | ||
| 163 | logger.info("Audio playback finished normally - disconnecting") | 158 | await voice_mgr.disconnect(channel.guild) |
| 164 | await voice_client.disconnect() | ||
| 165 | logger.info(f"Finished playing audio: {audio_url}") | ||
| 166 | except Exception as e: | 159 | except Exception as e: |
| 167 | logger.error(f"Error playing audio: {e}") | 160 | logger.error(f"Error playing audio: {e}") |
| 168 | if voice_client.is_connected(): | 161 | try: |
| 169 | logger.info("Audio playback failed - disconnecting") | 162 | await voice_mgr.disconnect(channel.guild) |
| 170 | await voice_client.disconnect() | 163 | except Exception: |
| 164 | pass | ||
| 171 | if channel.guild.system_channel: | 165 | if channel.guild.system_channel: |
| 172 | await channel.guild.system_channel.send( | 166 | await channel.guild.system_channel.send( |
| 173 | f"Błąd podczas odgrywania audio: {audio_url}" | 167 | f"Błąd podczas odgrywania audio: {audio_url}" |
