diff --git a/cogs/player.py b/cogs/player.py index 2c4871b..97b1e92 100644 --- a/cogs/player.py +++ b/cogs/player.py @@ -6,7 +6,7 @@ from typing import Optional, TYPE_CHECKING from dataclass.custom_embed import CustomEmbed from utils.config import get_debug_guilds -from utils.exceptions import EndOfQueueError, JockeyDeprecatedError, JockeyStartError +from utils.exceptions import EndOfQueueError, JockeyException, JockeyError from utils.jockey import Jockey from utils.jockey_helpers import create_error_embed, create_success_embed, list_chunks from utils.blanco import BlancoBot @@ -207,9 +207,9 @@ async def play(self, itx: Interaction, query: str = SlashOption(description='Que jockey = await self._get_jockey(itx) try: track_name = await jockey.play_impl(query, itx.user.id) - except JockeyStartError as e: + except JockeyError as e: await self._disconnect(itx=itx, reason=str(e)) - except JockeyDeprecatedError as e: + except JockeyException as e: await itx.followup.send(embed=create_error_embed(str(e))) else: return await itx.followup.send(embed=create_success_embed( diff --git a/database/migrations/__init__.py b/database/migrations/__init__.py index 57065fb..8ffaa00 100644 --- a/database/migrations/__init__.py +++ b/database/migrations/__init__.py @@ -15,5 +15,5 @@ def run_migrations(logger: 'Logger', con: 'Connection'): for file in listdir(path.dirname(__file__)): if file != path.basename(__file__) and file.endswith('.py'): logger.info(f'Running migration: {file}') - migration = import_module(f'utils.migrations.{file[:-3]}') + migration = import_module(f'database.migrations.{file[:-3]}') migration.run(con) diff --git a/utils/exceptions.py b/utils/exceptions.py index e94c2a1..17f0446 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -4,11 +4,17 @@ def __init__(self, reason): super().__init__(self.message) -class JockeyStartError(Exception): +class JockeyError(Exception): + """ + Raised when an error warrants disconnection from the voice channel. + """ pass -class JockeyDeprecatedError(Exception): +class JockeyException(Exception): + """ + Raised when an error does not warrant disconnection from the voice channel. + """ pass diff --git a/utils/jockey.py b/utils/jockey.py index fcc6812..9db4d48 100644 --- a/utils/jockey.py +++ b/utils/jockey.py @@ -247,19 +247,12 @@ async def play_impl(self, query: str, requester: int) -> str: query, requester ) - except IndexError: - raise JockeyStartError('No results found for query') - except LavalinkInvalidIdentifierError as e: - raise JockeyStartError(f'Invalid identifier: {e}') - except SpotifyInvalidURLError: - raise JockeyStartError('Can only play tracks, albums, and playlists from Spotify') - except SpotifyNoResultsError: - raise JockeyStartError('No results found for query, or playlist or album is empty') - except JockeyDeprecatedError: - # Just bubble this up + except JockeyException: raise except Exception as e: - raise JockeyStartError(f'Error parsing query: {e}') + if self.playing: + raise JockeyException(str(e)) + raise JockeyError(str(e)) # Add new tracks to queue old_size = len(self._queue) @@ -286,7 +279,7 @@ async def play_impl(self, query: str, requester: int) -> str: if self.is_shuffling: self._shuffle_indices = self._shuffle_indices[:old_size] - raise JockeyStartError(f'Failed to enqueue "{first.title}"\n{enqueue_result}') + raise JockeyError(f'Failed to enqueue "{first.title}"\n{enqueue_result}') # Send embed return first_name if len(new_tracks) == 1 else f'{len(new_tracks)} item(s)' diff --git a/utils/jockey_helpers.py b/utils/jockey_helpers.py index 6ab1252..7af9c29 100644 --- a/utils/jockey_helpers.py +++ b/utils/jockey_helpers.py @@ -60,7 +60,7 @@ async def parse_query(node: 'Node', spotify: Spotify, query: str, requester: int return await parse_sc_query(node, query, requester) # Direct URL playback is deprecated - raise JockeyDeprecatedError('Direct playback from unsupported URLs is deprecated') + raise JockeyException('Direct playback from unsupported URLs is deprecated') # Attempt to look for a matching track on Spotify yt_query = query