diff options
author | Parker <contact@pkrm.dev> | 2024-06-26 17:43:12 -0500 |
---|---|---|
committer | Parker <contact@pkrm.dev> | 2024-06-26 17:43:12 -0500 |
commit | cf7e9c0bc316c015e8822c8d8f2708be24b91bd1 (patch) | |
tree | 9b7088e0b45e0a3ad584e384cbded29642f4bb8b /code/cogs/music.py | |
parent | e418e06ce6feaade6adffe4041576e0b1596523d (diff) |
Consolidate config validation and variables to `config.py`
Diffstat (limited to 'code/cogs/music.py')
-rw-r--r-- | code/cogs/music.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/code/cogs/music.py b/code/cogs/music.py index e62c9e0..68870e1 100644 --- a/code/cogs/music.py +++ b/code/cogs/music.py @@ -3,16 +3,21 @@ from discord.ext import commands import lavalink from lavalink import errors -from global_variables import ( +from config import ( LAVALINK_HOST, LAVALINK_PASSWORD, LAVALINK_PORT, LOG, - CheckPlayerError, ) from ai_recommendations import add_song_recommendations +class CheckPlayerError(discord.app_commands.AppCommandError): + def __init__(self, info) -> None: + self.info = info + super().__init__() + + class LavalinkVoiceClient(discord.VoiceProtocol): """ This is the preferred way to handle external voice sending @@ -104,13 +109,15 @@ class Music(commands.Cog): host=LAVALINK_HOST, port=LAVALINK_PORT, password=LAVALINK_PASSWORD, - region='us-central', - connect=False + region="us-central", + connect=False, ) # Host, Port, Password, Region, Connect try: await node.get_version() except lavalink.errors.ClientError: - LOG.error("Authentication to lavalink node failed. Check your login credentials.") + LOG.error( + "Authentication to lavalink node failed. Check your login credentials." + ) else: await node.connect() LOG.info(f"Connected to lavalink node {node.name}") @@ -125,7 +132,9 @@ class Music(commands.Cog): async def create_player(interaction: discord.Interaction): """Create a player for the guild associated with the interaction, or raise an error""" try: - player = interaction.client.lavalink.player_manager.create(interaction.guild.id) + player = interaction.client.lavalink.player_manager.create( + interaction.guild.id + ) except errors.ClientError: raise CheckPlayerError( { |