From 5fba9bc4edfc672d0559637a389c7d7210d3e663 Mon Sep 17 00:00:00 2001 From: Draper <27962761+Drapersniper@users.noreply.github.com> Date: Thu, 23 Jul 2020 12:32:32 +0100 Subject: [PATCH] [Audio] Ensure TrackEnqueueError is always handled (#3879) Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com> --- redbot/cogs/audio/core/commands/player.py | 10 +++ redbot/cogs/audio/core/commands/playlists.py | 75 +++++++++++--------- redbot/cogs/audio/core/events/lavalink.py | 17 ++++- 3 files changed, 68 insertions(+), 34 deletions(-) diff --git a/redbot/cogs/audio/core/commands/player.py b/redbot/cogs/audio/core/commands/player.py index 10284f8be..d33398b66 100644 --- a/redbot/cogs/audio/core/commands/player.py +++ b/redbot/cogs/audio/core/commands/player.py @@ -576,6 +576,16 @@ class PlayerCommands(MixinMeta, metaclass=CompositeMetaClass): notify_channel = self.bot.get_channel(notify_channel) await self.send_embed_msg(notify_channel, title=_("Couldn't get a valid track.")) return + except TrackEnqueueError: + self.update_player_lock(ctx, False) + return await self.send_embed_msg( + ctx, + title=_("Unable to Get Track"), + description=_( + "I'm unable get a track from Lavalink at the moment, try again in a few " + "minutes." + ), + ) if not guild_data["auto_play"]: await ctx.invoke(self.command_audioset_autoplay_toggle) diff --git a/redbot/cogs/audio/core/commands/playlists.py b/redbot/cogs/audio/core/commands/playlists.py index 07c724e93..cb0ae37fa 100644 --- a/redbot/cogs/audio/core/commands/playlists.py +++ b/redbot/cogs/audio/core/commands/playlists.py @@ -22,7 +22,7 @@ from ...apis.playlist_interface import create_playlist, delete_playlist, get_all from ...audio_dataclasses import LocalPath, Query from ...audio_logging import IS_DEBUG, debug_exc_log from ...converters import ComplexScopeParser, ScopeParser -from ...errors import MissingGuild, TooManyMatches +from ...errors import MissingGuild, TooManyMatches, TrackEnqueueError from ...utils import PlaylistScope from ..abc import MixinMeta from ..cog_utils import CompositeMetaClass, LazyGreedyConverter, PlaylistConverter, _ @@ -1817,43 +1817,54 @@ class PlaylistCommands(MixinMeta, metaclass=CompositeMetaClass): uploaded_playlist_name = uploaded_playlist.get( "name", (file_url.split("/")[6]).split(".")[0] ) - if self.api_interface is not None and ( - not uploaded_playlist_url - or not self.match_yt_playlist(uploaded_playlist_url) - or not ( - await self.api_interface.fetch_track( + try: + if self.api_interface is not None and ( + not uploaded_playlist_url + or not self.match_yt_playlist(uploaded_playlist_url) + or not ( + await self.api_interface.fetch_track( + ctx, + player, + Query.process_input(uploaded_playlist_url, self.local_folder_current_path), + ) + )[0].tracks + ): + if version == "v3": + return await self._load_v3_playlist( + ctx, + scope, + uploaded_playlist_name, + uploaded_playlist_url, + track_list, + author, + guild, + ) + return await self._load_v2_playlist( ctx, - player, - Query.process_input(uploaded_playlist_url, self.local_folder_current_path), - ) - )[0].tracks - ): - if version == "v3": - return await self._load_v3_playlist( - ctx, - scope, - uploaded_playlist_name, - uploaded_playlist_url, track_list, + player, + uploaded_playlist_url, + uploaded_playlist_name, + scope, author, guild, ) - return await self._load_v2_playlist( - ctx, - track_list, - player, - uploaded_playlist_url, - uploaded_playlist_name, - scope, - author, - guild, + return await ctx.invoke( + self.command_playlist_save, + playlist_name=uploaded_playlist_name, + playlist_url=uploaded_playlist_url, + scope_data=(scope, author, guild, specified_user), + ) + except TrackEnqueueError: + self.update_player_lock(ctx, False) + return await self.send_embed_msg( + ctx, + title=_("Unable to Get Track"), + description=_( + "I'm unable get a track from Lavalink at the moment, try again in a few " + "minutes." + ), ) - return await ctx.invoke( - self.command_playlist_save, - playlist_name=uploaded_playlist_name, - playlist_url=uploaded_playlist_url, - scope_data=(scope, author, guild, specified_user), - ) @commands.cooldown(1, 60, commands.BucketType.member) @command_playlist.command( diff --git a/redbot/cogs/audio/core/events/lavalink.py b/redbot/cogs/audio/core/events/lavalink.py index 45fd7cb02..c54d888e3 100644 --- a/redbot/cogs/audio/core/events/lavalink.py +++ b/redbot/cogs/audio/core/events/lavalink.py @@ -5,7 +5,7 @@ import logging import discord import lavalink -from ...errors import DatabaseError +from ...errors import DatabaseError, TrackEnqueueError from ..abc import MixinMeta from ..cog_utils import CompositeMetaClass, _ @@ -62,12 +62,25 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass): await self.api_interface.autoplay(player, self.playlist_api) except DatabaseError: notify_channel = player.fetch("channel") + notify_channel = self.bot.get_channel(notify_channel) if notify_channel: - notify_channel = self.bot.get_channel(notify_channel) await self.send_embed_msg( notify_channel, title=_("Couldn't get a valid track.") ) return + except TrackEnqueueError: + notify_channel = player.fetch("channel") + notify_channel = self.bot.get_channel(notify_channel) + if notify_channel: + await self.send_embed_msg( + notify_channel, + title=_("Unable to Get Track"), + description=_( + "I'm unable get a track from Lavalink at the moment, try again in a few " + "minutes." + ), + ) + return if event_type == lavalink.LavalinkEvents.TRACK_START and notify: notify_channel = player.fetch("channel") if notify_channel: