From c687d9fa1d89fef8ddc7150d1487dfef07d11abb Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 20 Apr 2026 15:05:51 +0200 Subject: uploader.py and voice fixes Signed-off-by: salmonik --- cogs/music/audio_playback.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'cogs/music') diff --git a/cogs/music/audio_playback.py b/cogs/music/audio_playback.py index 28c6118..1c715de 100644 --- a/cogs/music/audio_playback.py +++ b/cogs/music/audio_playback.py @@ -137,8 +137,16 @@ class AudioPlaybackManager: return absolute_source, display_name, is_url @staticmethod - async def execute_playback(ctx, source, display_name, is_url): - """Execute the actual audio playback.""" + async def execute_playback(ctx, source, display_name, is_url, interrupt=True): + """Execute the actual audio playback. + + Args: + ctx: Discord context + source: Audio source path or URL + display_name: Name to display + is_url: Whether source is a URL + interrupt: If True, stop any currently playing audio. If False, skip if audio is playing. + """ target_channel = await AudioPlaybackManager.validate_voice_channel(ctx) if not target_channel: return False @@ -169,9 +177,12 @@ class AudioPlaybackManager: logger.info(f"Moving to voice channel: {target_channel.name}") await vc.move_to(target_channel) - # Stop any currently playing audio - if vc.is_playing() or vc.is_paused(): # type: ignore[union-attr] + # Stop any currently playing audio (if interrupt is True) + if interrupt and (vc.is_playing() or vc.is_paused()): # type: ignore[union-attr] vc.stop() # type: ignore[union-attr] + elif not interrupt and vc.is_playing(): # type: ignore[union-attr] + logger.info("Audio already playing and interrupt=False, skipping playback") + return False # Prepare audio source ( @@ -232,13 +243,14 @@ class AudioPlaybackManager: return prepared_source, display_name, is_url @staticmethod - async def play(ctx, source, delete_after_play=False): + async def play(ctx, source, delete_after_play=False, interrupt=True): """Play audio from a local file or URL. Args: ctx: Discord context source: Either a local file path or a URL to stream from delete_after_play: If True, delete the file after playing (only for local files) + interrupt: If True, stop any currently playing audio. If False, skip if audio is playing. """ # Validate and prepare source ( @@ -254,7 +266,7 @@ class AudioPlaybackManager: # Execute playback success = await AudioPlaybackManager.execute_playback( - ctx, prepared_source, display_name, is_url + ctx, prepared_source, display_name, is_url, interrupt ) # Cleanup if needed -- cgit v1.2.3