[Audio] Ensure TrackEnqueueError is always handled (#3879)

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
Draper 2020-07-23 12:32:32 +01:00 committed by GitHub
parent 0635921d6b
commit 5fba9bc4ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 34 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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: