diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/music/audio_playback.py | 10 | ||||
| -rw-r--r-- | cogs/music/play_commands.py | 11 | ||||
| -rw-r--r-- | tests/cogs/test_music_audio.py | 16 |
3 files changed, 14 insertions, 23 deletions
diff --git a/cogs/music/audio_playback.py b/cogs/music/audio_playback.py deleted file mode 100644 index 5206a96..0000000 --- a/cogs/music/audio_playback.py +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # This file is part of Senator Sperma | ||
| 2 | # Licensed under the GPL-3.0 License | ||
| 3 | # Copyright (C) 2026 Salmonik @ salmonik@tuta.io | ||
| 4 | # https://codeberg.org/salmonik/senator-sperma | ||
| 5 | |||
| 6 | # Re-export shim — all voice utilities now live in cogs.voice.VoiceManager. | ||
| 7 | # Kept so existing imports in play_commands.py and ai.py keep working. | ||
| 8 | # TODO: update importers and remove this file. | ||
| 9 | |||
| 10 | from cogs.voice import VoiceManager as AudioPlaybackManager # noqa: F401 | ||
diff --git a/cogs/music/play_commands.py b/cogs/music/play_commands.py index bdb021d..a90f901 100644 --- a/cogs/music/play_commands.py +++ b/cogs/music/play_commands.py | |||
| @@ -16,10 +16,11 @@ import discord | |||
| 16 | from discord.commands import OptionChoice | 16 | from discord.commands import OptionChoice |
| 17 | from discord.ext import commands | 17 | from discord.ext import commands |
| 18 | 18 | ||
| 19 | from cogs.music import audio_playback, media_processing | 19 | from cogs.music import media_processing |
| 20 | from cogs.utils.file_search import UniversalSearcher | 20 | from cogs.utils.file_search import UniversalSearcher |
| 21 | from cogs.utils.settings import get_uploadurl | 21 | from cogs.utils.settings import get_uploadurl |
| 22 | from cogs.utils.url_helper import clean_url_for_ytdlp | 22 | from cogs.utils.url_helper import clean_url_for_ytdlp |
| 23 | from cogs.voice import get_voice_manager | ||
| 23 | 24 | ||
| 24 | logger = logging.getLogger(__name__) | 25 | logger = logging.getLogger(__name__) |
| 25 | 26 | ||
| @@ -162,7 +163,7 @@ class PlayCommands(commands.Cog): | |||
| 162 | if not compressed_path: | 163 | if not compressed_path: |
| 163 | return | 164 | return |
| 164 | 165 | ||
| 165 | await audio_playback.AudioPlaybackManager.play( | 166 | await get_voice_manager(self.bot).play( |
| 166 | ctx, compressed_path, delete_after_play=True | 167 | ctx, compressed_path, delete_after_play=True |
| 167 | ) | 168 | ) |
| 168 | except Exception as e: | 169 | except Exception as e: |
| @@ -209,7 +210,7 @@ class PlayCommands(commands.Cog): | |||
| 209 | 210 | ||
| 210 | upload_task = asyncio.create_task(self._upload_to_copyparty_async(local_path)) | 211 | upload_task = asyncio.create_task(self._upload_to_copyparty_async(local_path)) |
| 211 | 212 | ||
| 212 | await audio_playback.AudioPlaybackManager.play( | 213 | await get_voice_manager(self.bot).play( |
| 213 | ctx, local_path, delete_after_play=True | 214 | ctx, local_path, delete_after_play=True |
| 214 | ) | 215 | ) |
| 215 | 216 | ||
| @@ -274,7 +275,7 @@ class PlayCommands(commands.Cog): | |||
| 274 | if compressed: | 275 | if compressed: |
| 275 | await self._handle_compressed_file_play(ctx, url) | 276 | await self._handle_compressed_file_play(ctx, url) |
| 276 | else: | 277 | else: |
| 277 | await audio_playback.AudioPlaybackManager.play(ctx, url) | 278 | await get_voice_manager(self.bot).play(ctx, url) |
| 278 | 279 | ||
| 279 | @discord.slash_command(name="grajcuj", description="grajcujmy wszyscy!") | 280 | @discord.slash_command(name="grajcuj", description="grajcujmy wszyscy!") |
| 280 | async def play( | 281 | async def play( |
| @@ -309,7 +310,7 @@ class PlayCommands(commands.Cog): | |||
| 309 | if file: | 310 | if file: |
| 310 | file_path: PathLike[str] | str = os.path.join(self.temp_dir, file.filename) | 311 | file_path: PathLike[str] | str = os.path.join(self.temp_dir, file.filename) |
| 311 | await file.save(file_path) | 312 | await file.save(file_path) |
| 312 | await audio_playback.AudioPlaybackManager.play(ctx, file_path) | 313 | await get_voice_manager(self.bot).play(ctx, file_path) |
| 313 | else: | 314 | else: |
| 314 | try: | 315 | try: |
| 315 | if EXTERNAL_URL_PATTERN.match(melodia.lower()): | 316 | if EXTERNAL_URL_PATTERN.match(melodia.lower()): |
diff --git a/tests/cogs/test_music_audio.py b/tests/cogs/test_music_audio.py index 150ad5d..98c6f6b 100644 --- a/tests/cogs/test_music_audio.py +++ b/tests/cogs/test_music_audio.py | |||
| @@ -6,7 +6,7 @@ from conftest import MockApplicationContext | |||
| 6 | 6 | ||
| 7 | @pytest.mark.asyncio | 7 | @pytest.mark.asyncio |
| 8 | async def test_validate_voice_channel_not_in_voice(): | 8 | async def test_validate_voice_channel_not_in_voice(): |
| 9 | from cogs.music.audio_playback import AudioPlaybackManager | 9 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 10 | 10 | ||
| 11 | mock_ctx = MagicMock() | 11 | mock_ctx = MagicMock() |
| 12 | mock_ctx.author.voice = None | 12 | mock_ctx.author.voice = None |
| @@ -20,7 +20,7 @@ async def test_validate_voice_channel_not_in_voice(): | |||
| 20 | 20 | ||
| 21 | @pytest.mark.asyncio | 21 | @pytest.mark.asyncio |
| 22 | async def test_validate_voice_channel_in_voice(): | 22 | async def test_validate_voice_channel_in_voice(): |
| 23 | from cogs.music.audio_playback import AudioPlaybackManager | 23 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 24 | 24 | ||
| 25 | mock_channel = MagicMock() | 25 | mock_channel = MagicMock() |
| 26 | mock_ctx = MagicMock() | 26 | mock_ctx = MagicMock() |
| @@ -35,7 +35,7 @@ async def test_validate_voice_channel_in_voice(): | |||
| 35 | 35 | ||
| 36 | @pytest.mark.asyncio | 36 | @pytest.mark.asyncio |
| 37 | async def test_prepare_file_source_file_not_found(): | 37 | async def test_prepare_file_source_file_not_found(): |
| 38 | from cogs.music.audio_playback import AudioPlaybackManager | 38 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 39 | 39 | ||
| 40 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") | 40 | display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") |
| 41 | 41 | ||
| @@ -45,7 +45,7 @@ async def test_prepare_file_source_file_not_found(): | |||
| 45 | 45 | ||
| 46 | @pytest.mark.asyncio | 46 | @pytest.mark.asyncio |
| 47 | async def test_prepare_file_source_absolute_path(): | 47 | async def test_prepare_file_source_absolute_path(): |
| 48 | from cogs.music.audio_playback import AudioPlaybackManager | 48 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 49 | 49 | ||
| 50 | with patch('os.path.exists', return_value=True): | 50 | with patch('os.path.exists', return_value=True): |
| 51 | with patch('os.path.isabs', return_value=True): | 51 | with patch('os.path.isabs', return_value=True): |
| @@ -57,7 +57,7 @@ async def test_prepare_file_source_absolute_path(): | |||
| 57 | 57 | ||
| 58 | @pytest.mark.asyncio | 58 | @pytest.mark.asyncio |
| 59 | async def test_prepare_source_url(): | 59 | async def test_prepare_source_url(): |
| 60 | from cogs.music.audio_playback import AudioPlaybackManager | 60 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 61 | 61 | ||
| 62 | source, _, is_url = await AudioPlaybackManager.prepare_source("https://example.com/stream") | 62 | source, _, is_url = await AudioPlaybackManager.prepare_source("https://example.com/stream") |
| 63 | 63 | ||
| @@ -67,7 +67,7 @@ async def test_prepare_source_url(): | |||
| 67 | 67 | ||
| 68 | @pytest.mark.asyncio | 68 | @pytest.mark.asyncio |
| 69 | async def test_prepare_source_local_file(): | 69 | async def test_prepare_source_local_file(): |
| 70 | from cogs.music.audio_playback import AudioPlaybackManager | 70 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 71 | 71 | ||
| 72 | with patch('os.path.exists', return_value=True): | 72 | with patch('os.path.exists', return_value=True): |
| 73 | source, display_name, is_url = await AudioPlaybackManager.prepare_source("/tmp/test.mp3") | 73 | source, display_name, is_url = await AudioPlaybackManager.prepare_source("/tmp/test.mp3") |
| @@ -78,7 +78,7 @@ async def test_prepare_source_local_file(): | |||
| 78 | 78 | ||
| 79 | @pytest.mark.asyncio | 79 | @pytest.mark.asyncio |
| 80 | async def test_cleanup_temp_file(): | 80 | async def test_cleanup_temp_file(): |
| 81 | from cogs.music.audio_playback import AudioPlaybackManager | 81 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 82 | 82 | ||
| 83 | with patch('os.path.exists', return_value=True): | 83 | with patch('os.path.exists', return_value=True): |
| 84 | with patch('os.remove'): | 84 | with patch('os.remove'): |
| @@ -87,7 +87,7 @@ async def test_cleanup_temp_file(): | |||
| 87 | 87 | ||
| 88 | @pytest.mark.asyncio | 88 | @pytest.mark.asyncio |
| 89 | async def test_cleanup_temp_file_not_exists(): | 89 | async def test_cleanup_temp_file_not_exists(): |
| 90 | from cogs.music.audio_playback import AudioPlaybackManager | 90 | from cogs.voice import VoiceManager as AudioPlaybackManager |
| 91 | 91 | ||
| 92 | with patch('os.path.exists', return_value=False): | 92 | with patch('os.path.exists', return_value=False): |
| 93 | await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") | 93 | await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") |
