Skip to content

Commit

Permalink
Merge pull request #15 from jareddantis-bots/fix/v0.2.2
Browse files Browse the repository at this point in the history
v0.2.2
  • Loading branch information
jareddantis authored Jul 14, 2023
2 parents 8118845 + 4a8dfec commit cee5d29
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
6 changes: 3 additions & 3 deletions cogs/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion database/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 8 additions & 2 deletions utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
17 changes: 5 additions & 12 deletions utils/jockey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)'
Expand Down
2 changes: 1 addition & 1 deletion utils/jockey_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cee5d29

Please sign in to comment.