From 4663f260b55de0975661fda1c00f60d2ca6e4506 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 20 May 2026 15:40:18 +0200 Subject: 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 --- cogs/cron.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'cogs/cron.py') 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): if isinstance(channel, discord.VoiceChannel): voice_mgr = get_voice_manager(self.bot) - voice_client = await voice_mgr.join_channel(channel) - if not voice_client: - if channel.guild.system_channel: - await channel.guild.system_channel.send( - "Nie udano się połączyć z kanałem głosowym" - ) - return try: audio_source = discord.FFmpegPCMAudio(audio_url) - voice_client.play(audio_source) + success = await voice_mgr.play_source(channel, audio_source) - while voice_client.is_playing(): - await asyncio.sleep(1) + if success: + logger.info(f"Finished playing audio: {audio_url}") + else: + raise Exception("Playback failed") - logger.info("Audio playback finished normally - disconnecting") - await voice_client.disconnect() - logger.info(f"Finished playing audio: {audio_url}") + await voice_mgr.disconnect(channel.guild) except Exception as e: logger.error(f"Error playing audio: {e}") - if voice_client.is_connected(): - logger.info("Audio playback failed - disconnecting") - await voice_client.disconnect() + try: + await voice_mgr.disconnect(channel.guild) + except Exception: + pass if channel.guild.system_channel: await channel.guild.system_channel.send( f"Błąd podczas odgrywania audio: {audio_url}" -- cgit v1.2.3