Skip to content

Commit

Permalink
Apply new error names from Cog-Creators/Red-Lavalink#115
Browse files Browse the repository at this point in the history
  • Loading branch information
Drapersniper committed Mar 16, 2022
1 parent 45be972 commit 9305252
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
9 changes: 5 additions & 4 deletions redbot/cogs/audio/core/commands/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import discord
import lavalink
from lavalink import NodeNotFound, PlayerNotFound

from redbot.core import commands
from redbot.core.i18n import Translator
Expand Down Expand Up @@ -178,7 +179,7 @@ async def command_queue_clear(self, ctx: commands.Context):
"""Clears the queue."""
try:
player = lavalink.get_player(ctx.guild.id)
except KeyError:
except (NodeNotFound, PlayerNotFound):
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
Expand Down Expand Up @@ -209,7 +210,7 @@ async def command_queue_clean(self, ctx: commands.Context):
"""Removes songs from the queue if the requester is not in the voice channel."""
try:
player = lavalink.get_player(ctx.guild.id)
except KeyError:
except (NodeNotFound, PlayerNotFound):
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
dj_enabled = self._dj_status_cache.setdefault(
ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled()
Expand Down Expand Up @@ -256,7 +257,7 @@ async def command_queue_cleanself(self, ctx: commands.Context):

try:
player = lavalink.get_player(ctx.guild.id)
except KeyError:
except (NodeNotFound, PlayerNotFound):
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
if not self._player_check(ctx) or not player.queue:
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
Expand Down Expand Up @@ -288,7 +289,7 @@ async def command_queue_search(self, ctx: commands.Context, *, search_words: str
"""Search the queue."""
try:
player = lavalink.get_player(ctx.guild.id)
except KeyError:
except (NodeNotFound, PlayerNotFound):
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
if not self._player_check(ctx) or not player.queue:
return await self.send_embed_msg(ctx, title=_("There's nothing in the queue."))
Expand Down
3 changes: 2 additions & 1 deletion redbot/cogs/audio/core/events/dpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from aiohttp import ClientConnectorError
from discord.ext.commands import CheckFailure
from lavalink import NodeNotFound, PlayerNotFound

from redbot.core import commands
from redbot.core.i18n import Translator
Expand Down Expand Up @@ -320,7 +321,7 @@ async def on_voice_state_update(
):
try:
player = lavalink.get_player(channel.guild.id)
except (KeyError, AttributeError):
except (NodeNotFound, PlayerNotFound, AttributeError):
pass
else:
if player.channel.id == channel.id:
Expand Down
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/tasks/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def lavalink_attempt_connect(self, timeout: int = 50, manual: bool = False
resume_key=f"Red-Core-Audio-{self.bot.user.id}-{data_manager.instance_name}",
secured=secured,
)
except lavalink.enums.AbortingConnectionException:
except lavalink.AbortingNodeConnectionException:
await lavalink.close(self.bot)
log.warning("Connection attempt to Lavalink node aborted")
return
Expand Down
9 changes: 3 additions & 6 deletions redbot/cogs/audio/core/tasks/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional

import lavalink
from lavalink import NodeNotFound, PlayerNotFound

from redbot.core.data_manager import cog_data_path
from redbot.core.i18n import Translator
Expand Down Expand Up @@ -109,9 +110,7 @@ async def restore_players(self):
else:
try:
player = lavalink.get_player(guild_id)
except IndexError:
player = None
except KeyError:
except (NodeNotFound, PlayerNotFound):
player = None
vc = 0
guild_data = await self.config.guild_from_id(guild.id).all()
Expand Down Expand Up @@ -182,9 +181,7 @@ async def restore_players(self):
else:
try:
player = lavalink.get_player(guild_id)
except IndexError:
player = None
except KeyError:
except (NodeNotFound, PlayerNotFound):
player = None
if player is None:
guild_data = await self.config.guild_from_id(guild.id).all()
Expand Down
5 changes: 3 additions & 2 deletions redbot/cogs/audio/core/utilities/equalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import discord
import lavalink
from lavalink import NodeNotFound, PlayerNotFound

from redbot.core import commands
from redbot.core.utils.chat_formatting import box
Expand All @@ -27,7 +28,7 @@ async def _apply_gain(self, guild_id: int, band: int, gain: float) -> None:

try:
await lavalink.get_player(guild_id).node.send({**const})
except (KeyError, IndexError):
except (NodeNotFound, PlayerNotFound):
pass

async def _apply_gains(self, guild_id: int, gains: List[float]) -> None:
Expand All @@ -39,7 +40,7 @@ async def _apply_gains(self, guild_id: int, gains: List[float]) -> None:

try:
await lavalink.get_player(guild_id).node.send({**const})
except (KeyError, IndexError):
except (NodeNotFound, PlayerNotFound):
pass

async def _eq_check(self, ctx: commands.Context, player: lavalink.Player) -> None:
Expand Down
6 changes: 4 additions & 2 deletions redbot/cogs/audio/core/utilities/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lavalink

from discord.embeds import EmptyEmbed
from lavalink import NodeNotFound, PlayerNotFound

from redbot.core import commands
from redbot.core.i18n import Translator
from redbot.core.utils import AsyncIter
Expand Down Expand Up @@ -208,7 +210,7 @@ def _player_check(self, ctx: commands.Context) -> bool:
try:
lavalink.get_player(ctx.guild.id)
return True
except (IndexError, KeyError):
except (NodeNotFound, PlayerNotFound):
return False

async def self_deafen(self, player: lavalink.Player) -> None:
Expand Down Expand Up @@ -687,7 +689,7 @@ async def set_player_settings(self, ctx: commands.Context) -> None:
async def maybe_move_player(self, ctx: commands.Context) -> bool:
try:
player = lavalink.get_player(ctx.guild.id)
except KeyError:
except PlayerNotFound:
return False
try:
in_channel = sum(
Expand Down

0 comments on commit 9305252

Please sign in to comment.