From a16823bcaa5c60a5af170de16b2d23fee3b4add5 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Fri, 31 May 2024 22:24:38 +0100 Subject: [PATCH 1/8] Update controller.py --- redbot/cogs/audio/core/commands/controller.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 8cc9714697b..605dc885af2 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -30,6 +30,10 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): @commands.bot_has_permissions(embed_links=True) async def command_disconnect(self, ctx: commands.Context): """Disconnect from the voice channel.""" + + # Check if the user is in a voice channel. + if ctx.author.voice is None: + return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) if not self._player_check(ctx): return await self.send_embed_msg(ctx, title=_("Nothing playing.")) else: @@ -61,6 +65,12 @@ async def command_disconnect(self, ctx: commands.Context): title=_("Unable to Disconnect"), description=_("You need the DJ role to disconnect."), ) + if dj_enabled and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable to Disconnect"), + description=_("You need the DJ role to disconnect."), + ) await self.send_embed_msg(ctx, title=_("Disconnecting...")) self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) From 4e77eb2b28feedeafce635a17138ec56f83c69c7 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Fri, 31 May 2024 22:49:11 +0100 Subject: [PATCH 2/8] Update controller.py --- redbot/cogs/audio/core/commands/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 605dc885af2..5096255a7a3 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -30,7 +30,7 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): @commands.bot_has_permissions(embed_links=True) async def command_disconnect(self, ctx: commands.Context): """Disconnect from the voice channel.""" - + # Check if the user is in a voice channel. if ctx.author.voice is None: return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) From bae4e4104f32bba63139f440709ffc3842245b52 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Sat, 1 Jun 2024 10:44:46 +0100 Subject: [PATCH 3/8] fix double code --- redbot/cogs/audio/core/commands/controller.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 5096255a7a3..ece068a068f 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -65,13 +65,6 @@ async def command_disconnect(self, ctx: commands.Context): title=_("Unable to Disconnect"), description=_("You need the DJ role to disconnect."), ) - if dj_enabled and not can_skip: - return await self.send_embed_msg( - ctx, - title=_("Unable to Disconnect"), - description=_("You need the DJ role to disconnect."), - ) - await self.send_embed_msg(ctx, title=_("Disconnecting...")) self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) self.update_player_lock(ctx, False) From 1fec6d1e7ae67aad55a909f7bf2f0b766e8db0d9 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Sat, 1 Jun 2024 18:55:15 +0100 Subject: [PATCH 4/8] Update controller.py seeing if this will allow someone to disconnect without being in vc if no one is there --- redbot/cogs/audio/core/commands/controller.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index ece068a068f..f8ed2279a30 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -31,6 +31,30 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): async def command_disconnect(self, ctx: commands.Context): """Disconnect from the voice channel.""" + player = lavalink.get_player(ctx.guild.id) + + # Check if the voice channel is empty. + if ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1: + await self.send_embed_msg(ctx, title=_("Disconnecting...")) + self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) + self.update_player_lock(ctx, False) + eq = player.fetch("eq") + player.queue = [] + player.store("playing_song", None) + player.store("autoplay_notified", False) + if eq: + await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) + await player.stop() + await player.disconnect() + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( + [] + ) + self._ll_guild_updates.discard(ctx.guild.id) + await self.api_interface.persistent_queue_api.drop(ctx.guild.id) + return await self.send_embed_msg( + ctx, title=_("Disconnected because the channel was empty.") + ) + # Check if the user is in a voice channel. if ctx.author.voice is None: return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) @@ -41,7 +65,6 @@ async def command_disconnect(self, ctx: commands.Context): ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() ) vote_enabled = await self.config.guild(ctx.guild).vote_enabled() - player = lavalink.get_player(ctx.guild.id) can_skip = await self._can_instaskip(ctx, ctx.author) if ( (vote_enabled or (vote_enabled and dj_enabled)) From 31ee06db6d979bd685f99073eba0c4e4057ec18f Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:00:06 +0100 Subject: [PATCH 5/8] Update controller.py try 2 sorry --- redbot/cogs/audio/core/commands/controller.py | 85 +++++++++---------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index f8ed2279a30..1da95b22308 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -55,55 +55,54 @@ async def command_disconnect(self, ctx: commands.Context): ctx, title=_("Disconnected because the channel was empty.") ) - # Check if the user is in a voice channel. + # Check if the user is in a voice channel or not. if ctx.author.voice is None: return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) + if not self._player_check(ctx): return await self.send_embed_msg(ctx, title=_("Nothing playing.")) - else: - dj_enabled = self._dj_status_cache.setdefault( - ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() + dj_enabled = self._dj_status_cache.setdefault( + ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() + ) + vote_enabled = await self.config.guild(ctx.guild).vote_enabled() + can_skip = await self._can_instaskip(ctx, ctx.author) + if ( + (vote_enabled or (vote_enabled and dj_enabled)) + and not can_skip + and not await self.is_requester_alone(ctx) + ): + return await self.send_embed_msg( + ctx, + title=_("Unable To Disconnect"), + description=_("There are other people listening - vote to skip instead."), ) - vote_enabled = await self.config.guild(ctx.guild).vote_enabled() - can_skip = await self._can_instaskip(ctx, ctx.author) - if ( - (vote_enabled or (vote_enabled and dj_enabled)) - and not can_skip - and not await self.is_requester_alone(ctx) - ): - return await self.send_embed_msg( - ctx, - title=_("Unable To Disconnect"), - description=_("There are other people listening - vote to skip instead."), - ) - if dj_enabled and not vote_enabled and not can_skip: - return await self.send_embed_msg( - ctx, - title=_("Unable To Disconnect"), - description=_("You need the DJ role to disconnect."), - ) - if dj_enabled and not can_skip: - return await self.send_embed_msg( - ctx, - title=_("Unable to Disconnect"), - description=_("You need the DJ role to disconnect."), - ) - await self.send_embed_msg(ctx, title=_("Disconnecting...")) - self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) - self.update_player_lock(ctx, False) - eq = player.fetch("eq") - player.queue = [] - player.store("playing_song", None) - player.store("autoplay_notified", False) - if eq: - await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) - await player.stop() - await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( - [] + if dj_enabled and not vote_enabled and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable To Disconnect"), + description=_("You need the DJ role to disconnect."), ) - self._ll_guild_updates.discard(ctx.guild.id) - await self.api_interface.persistent_queue_api.drop(ctx.guild.id) + if dj_enabled and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable to Disconnect"), + description=_("You need the DJ role to disconnect."), + ) + + await self.send_embed_msg(ctx, title=_("Disconnecting...")) + self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) + self.update_player_lock(ctx, False) + eq = player.fetch("eq") + player.queue = [] + player.store("playing_song", None) + player.store("autoplay_notified", False) + if eq: + await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) + await player.stop() + await player.disconnect() + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) + self._ll_guild_updates.discard(ctx.guild.id) + await self.api_interface.persistent_queue_api.drop(ctx.guild.id) @commands.command(name="now") @commands.guild_only() From 8917bea7c98e7e22e90c06ba6e54120ba5d51599 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Sat, 1 Jun 2024 19:02:38 +0100 Subject: [PATCH 6/8] Revert "Update controller.py" This reverts commit 31ee06db6d979bd685f99073eba0c4e4057ec18f. --- redbot/cogs/audio/core/commands/controller.py | 85 ++++++++++--------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 1da95b22308..f8ed2279a30 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -55,54 +55,55 @@ async def command_disconnect(self, ctx: commands.Context): ctx, title=_("Disconnected because the channel was empty.") ) - # Check if the user is in a voice channel or not. + # Check if the user is in a voice channel. if ctx.author.voice is None: return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) - if not self._player_check(ctx): return await self.send_embed_msg(ctx, title=_("Nothing playing.")) - dj_enabled = self._dj_status_cache.setdefault( - ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() - ) - vote_enabled = await self.config.guild(ctx.guild).vote_enabled() - can_skip = await self._can_instaskip(ctx, ctx.author) - if ( - (vote_enabled or (vote_enabled and dj_enabled)) - and not can_skip - and not await self.is_requester_alone(ctx) - ): - return await self.send_embed_msg( - ctx, - title=_("Unable To Disconnect"), - description=_("There are other people listening - vote to skip instead."), + else: + dj_enabled = self._dj_status_cache.setdefault( + ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() ) - if dj_enabled and not vote_enabled and not can_skip: - return await self.send_embed_msg( - ctx, - title=_("Unable To Disconnect"), - description=_("You need the DJ role to disconnect."), + vote_enabled = await self.config.guild(ctx.guild).vote_enabled() + can_skip = await self._can_instaskip(ctx, ctx.author) + if ( + (vote_enabled or (vote_enabled and dj_enabled)) + and not can_skip + and not await self.is_requester_alone(ctx) + ): + return await self.send_embed_msg( + ctx, + title=_("Unable To Disconnect"), + description=_("There are other people listening - vote to skip instead."), + ) + if dj_enabled and not vote_enabled and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable To Disconnect"), + description=_("You need the DJ role to disconnect."), + ) + if dj_enabled and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable to Disconnect"), + description=_("You need the DJ role to disconnect."), + ) + await self.send_embed_msg(ctx, title=_("Disconnecting...")) + self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) + self.update_player_lock(ctx, False) + eq = player.fetch("eq") + player.queue = [] + player.store("playing_song", None) + player.store("autoplay_notified", False) + if eq: + await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) + await player.stop() + await player.disconnect() + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( + [] ) - if dj_enabled and not can_skip: - return await self.send_embed_msg( - ctx, - title=_("Unable to Disconnect"), - description=_("You need the DJ role to disconnect."), - ) - - await self.send_embed_msg(ctx, title=_("Disconnecting...")) - self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) - self.update_player_lock(ctx, False) - eq = player.fetch("eq") - player.queue = [] - player.store("playing_song", None) - player.store("autoplay_notified", False) - if eq: - await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) - await player.stop() - await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) - self._ll_guild_updates.discard(ctx.guild.id) - await self.api_interface.persistent_queue_api.drop(ctx.guild.id) + self._ll_guild_updates.discard(ctx.guild.id) + await self.api_interface.persistent_queue_api.drop(ctx.guild.id) @commands.command(name="now") @commands.guild_only() From bd94693fc5c63f5941dc7193689a34e72e9bca18 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:45:37 +0100 Subject: [PATCH 7/8] Update controller.py --- redbot/cogs/audio/core/commands/controller.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index f8ed2279a30..c0d2c356a21 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -33,7 +33,7 @@ async def command_disconnect(self, ctx: commands.Context): player = lavalink.get_player(ctx.guild.id) - # Check if the voice channel is empty. + # Check if the voice channel is empty except for the bot. if ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1: await self.send_embed_msg(ctx, title=_("Disconnecting...")) self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) @@ -46,18 +46,16 @@ async def command_disconnect(self, ctx: commands.Context): await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) await player.stop() await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( - [] - ) + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) self._ll_guild_updates.discard(ctx.guild.id) await self.api_interface.persistent_queue_api.drop(ctx.guild.id) - return await self.send_embed_msg( - ctx, title=_("Disconnected because the channel was empty.") - ) + return await self.send_embed_msg(ctx, title=_("Disconnected because the channel was empty.")) + - # Check if the user is in a voice channel. - if ctx.author.voice is None: + # Check if the user is in a voice channel or if the voice channel is empty except for the bot. + if ctx.author.voice is None and not (ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1): return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) + if not self._player_check(ctx): return await self.send_embed_msg(ctx, title=_("Nothing playing.")) else: @@ -99,12 +97,11 @@ async def command_disconnect(self, ctx: commands.Context): await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) await player.stop() await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( - [] - ) + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) self._ll_guild_updates.discard(ctx.guild.id) await self.api_interface.persistent_queue_api.drop(ctx.guild.id) + @commands.command(name="now") @commands.guild_only() @commands.bot_has_permissions(embed_links=True) From cb4eed9ddacf234e80f1baf454cc30c803b9bf89 Mon Sep 17 00:00:00 2001 From: Ben Cos <52817096+BenCos17@users.noreply.github.com> Date: Wed, 7 Aug 2024 21:59:36 +0100 Subject: [PATCH 8/8] add black formatting --- redbot/cogs/audio/core/commands/controller.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index c0d2c356a21..3c10a3e479e 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -46,14 +46,19 @@ async def command_disconnect(self, ctx: commands.Context): await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) await player.stop() await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( + [] + ) self._ll_guild_updates.discard(ctx.guild.id) await self.api_interface.persistent_queue_api.drop(ctx.guild.id) - return await self.send_embed_msg(ctx, title=_("Disconnected because the channel was empty.")) - + return await self.send_embed_msg( + ctx, title=_("Disconnected from empty voice channel.") + ) # Check if the user is in a voice channel or if the voice channel is empty except for the bot. - if ctx.author.voice is None and not (ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1): + if ctx.author.voice is None and not ( + ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1 + ): return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) if not self._player_check(ctx): @@ -97,11 +102,12 @@ async def command_disconnect(self, ctx: commands.Context): await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) await player.stop() await player.disconnect() - await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set([]) + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( + [] + ) self._ll_guild_updates.discard(ctx.guild.id) await self.api_interface.persistent_queue_api.drop(ctx.guild.id) - @commands.command(name="now") @commands.guild_only() @commands.bot_has_permissions(embed_links=True)