From d528bb71be0a7548f1acb94084571cc7c0d98773 Mon Sep 17 00:00:00 2001 From: Jared Dantis Date: Fri, 14 Jul 2023 17:54:28 +0800 Subject: [PATCH 1/3] migrations: Fix dynamic import path --- database/migrations/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 836b7521801f451a451bbd549100ca9d21a84f51 Mon Sep 17 00:00:00 2001 From: Jared Dantis Date: Fri, 14 Jul 2023 17:59:53 +0800 Subject: [PATCH 2/3] exceptions: Rename to JockeyError and JockeyException This is to better differentiate between non-exiting (no disconnection from voice) Exceptions and fatal Errors --- cogs/player.py | 6 +++--- utils/exceptions.py | 4 ++-- utils/jockey.py | 14 +++++++------- utils/jockey_helpers.py | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) 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/utils/exceptions.py b/utils/exceptions.py index e94c2a1..da0c85f 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -4,11 +4,11 @@ def __init__(self, reason): super().__init__(self.message) -class JockeyStartError(Exception): +class JockeyError(Exception): pass -class JockeyDeprecatedError(Exception): +class JockeyException(Exception): pass diff --git a/utils/jockey.py b/utils/jockey.py index fcc6812..b86e085 100644 --- a/utils/jockey.py +++ b/utils/jockey.py @@ -248,18 +248,18 @@ async def play_impl(self, query: str, requester: int) -> str: requester ) except IndexError: - raise JockeyStartError('No results found for query') + raise JockeyError('No results found for query') except LavalinkInvalidIdentifierError as e: - raise JockeyStartError(f'Invalid identifier: {e}') + raise JockeyError(f'Invalid identifier: {e}') except SpotifyInvalidURLError: - raise JockeyStartError('Can only play tracks, albums, and playlists from Spotify') + raise JockeyError('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: + raise JockeyError('No results found for query, or playlist or album is empty') + except JockeyException: # Just bubble this up raise except Exception as e: - raise JockeyStartError(f'Error parsing query: {e}') + raise JockeyError(f'Error parsing query: {e}') # Add new tracks to queue old_size = len(self._queue) @@ -286,7 +286,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 From 4a8dfec16fb91b7d895551113e4dcf046c0617c4 Mon Sep 17 00:00:00 2001 From: Jared Dantis Date: Fri, 14 Jul 2023 18:05:49 +0800 Subject: [PATCH 3/3] jockey: Don't force disconnect while already playing --- utils/exceptions.py | 6 ++++++ utils/jockey.py | 13 +++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/utils/exceptions.py b/utils/exceptions.py index da0c85f..17f0446 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -5,10 +5,16 @@ def __init__(self, reason): class JockeyError(Exception): + """ + Raised when an error warrants disconnection from the voice channel. + """ pass 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 b86e085..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 JockeyError('No results found for query') - except LavalinkInvalidIdentifierError as e: - raise JockeyError(f'Invalid identifier: {e}') - except SpotifyInvalidURLError: - raise JockeyError('Can only play tracks, albums, and playlists from Spotify') - except SpotifyNoResultsError: - raise JockeyError('No results found for query, or playlist or album is empty') except JockeyException: - # Just bubble this up raise except Exception as e: - raise JockeyError(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)