diff --git a/cogs/music.py b/cogs/music.py index 91a401f..02cb4ee 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -241,15 +241,16 @@ class Music(BaseCog): async def play(self, ctx: CustomContext): """Start the radio""" # Get the player for this guild from cache. - player = ctx.get_player() - if player.is_connected: + if ctx.player.is_connected: await ctx.send("Already connected") return - await self.fill_player_queue(player, self.bot.config["queue_buffer_size"] + 1) + await self.fill_player_queue( + ctx.player, self.bot.config["queue_buffer_size"] + 1 + ) - if not player.is_playing: - await player.play() + if not ctx.player.is_playing: + await ctx.player.play() await EmbedGenerator.Title(ctx, "*⃣ | Connected.") return @@ -257,21 +258,19 @@ class Music(BaseCog): @commands.command(name="skip", aliases=["next"]) async def skip(self, ctx: CustomContext): """Skip the current song""" - player = ctx.get_player() - await player.skip() + await ctx.player.skip() await ctx.send("Skipped current song") @commands.command(name="queue") async def queue(self, ctx: CustomContext): """Display the current radio queue""" - player = ctx.get_player() embed_color = self.bot.colors["embed"] embed = Embed(title="Coming Up...", colour=embed_color) - if len(player.queue) > 0: + if len(ctx.player.queue) > 0: embed.description = "\n".join( f"{index}. [{track.title}]({track.uri})" - for index, track in enumerate(player.queue, 1) + for index, track in enumerate(ctx.player.queue, 1) ) else: embed.description = "We are still determining a playlist" @@ -281,11 +280,9 @@ class Music(BaseCog): @commands.command(name="disconnect", aliases=["dc", "stop"]) async def disconnect(self, ctx: CustomContext): """Disconnects the radio from the channel""" - player = ctx.get_player() - if not ctx.author.voice or ( - player.is_connected - and ctx.author.voice.channel.id != int(player.channel_id) + ctx.player.is_connected + and ctx.author.voice.channel.id != int(ctx.player.channel_id) ): # Abuse prevention. Users not in voice channels, or not in the same voice channel as the bot # may not disconnect the bot. @@ -294,18 +291,17 @@ class Music(BaseCog): # Clear the queue to ensure old tracks don't start playing # when someone else queues something. - player.queue.clear() + ctx.player.queue.clear() # Stop the current track so Lavalink consumes less resources. - await player.stop() + await ctx.player.stop() # Disconnect from the voice channel. await ctx.voice_client.disconnect(force=True) await EmbedGenerator.Title(ctx, "*⃣ | Disconnected.") @commands.command(name="now") async def now_playing(self, ctx: CustomContext): - player: DefaultPlayer = self.bot.lavalink.player_manager.get(ctx.guild.id) - track = player.current - embed = await self.create_track_embed(track) + """Displays information about the currently played track""" + embed = await self.create_track_embed(ctx.player.current) await ctx.send(embed=embed) diff --git a/cogs/settings.py b/cogs/settings.py index d7f13a8..fee02a4 100644 --- a/cogs/settings.py +++ b/cogs/settings.py @@ -30,7 +30,7 @@ class SettingsCog(BaseCog, name="Settings"): voicechannel_id = ctx.author.voice.channel.id textchannel_id = ctx.message.channel.id await AutoJoin.update_channel( - ctx.get_redis(), ctx.guild.id, voicechannel_id, textchannel_id + ctx.redis, ctx.guild.id, voicechannel_id, textchannel_id ) await EmbedGenerator.Message(ctx, "Autojoin", "`enabled`") @@ -39,7 +39,7 @@ class SettingsCog(BaseCog, name="Settings"): @commands.cooldown(rate=1, per=5, type=commands.BucketType.user) async def autojoin_del(self, ctx: CustomContext): """Disable the bot automatically joining""" - await AutoJoin.del_channel(ctx.get_redis(), ctx.guild.id) + await AutoJoin.del_channel(ctx.redis, ctx.guild.id) await EmbedGenerator.Message(ctx, "Autojoin", "`disabled`") diff --git a/context.py b/context.py index d5051ea..3f41dc7 100644 --- a/context.py +++ b/context.py @@ -5,10 +5,12 @@ from lavalink.models import DefaultPlayer class CustomContext(commands.Context): - def get_redis(self) -> Redis: + @property + def redis(self) -> Redis: return self.bot._redis_client - def get_player(self) -> DefaultPlayer: + @property + def player(self) -> DefaultPlayer: if hasattr(self.bot, "lavalink"): return self.bot.lavalink.player_manager.get(self.guild.id)