Skip to content

Commit 3498157

Browse files
committed
Rework the if statements and add comments documenting the behavior
1 parent a0c3580 commit 3498157

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

redbot/cogs/audio/core/commands/controller.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,34 @@ async def command_disconnect(self, ctx: commands.Context):
4646
vote_enabled = await self.config.guild(ctx.guild).vote_enabled()
4747
can_skip = await self._can_instaskip(ctx, ctx.author)
4848
is_alone = await self.is_requester_alone(ctx, channel)
49-
if (vote_enabled or (vote_enabled and dj_enabled)) and not can_skip and not is_alone:
49+
if is_alone or can_skip:
50+
# User can always disconnect the bot, if there is nobody else in the player's channel
51+
# or when they can instaskip.
52+
pass
53+
# There is someone else in the player's channel and the author can't instaskip,
54+
# we have to ensure that none of the following are true for them to be allowed to DC:
55+
elif vote_enabled:
5056
return await self.send_embed_msg(
5157
ctx,
5258
title=_("Unable To Disconnect"),
5359
description=_("There are other people listening - vote to skip instead."),
5460
)
55-
if dj_enabled and not vote_enabled and not can_skip:
61+
elif dj_enabled:
62+
# DJ role would have granted the user the ability to instaskip,
63+
# so we know they don't have it
5664
return await self.send_embed_msg(
5765
ctx,
5866
title=_("Unable To Disconnect"),
5967
description=_("You need the DJ role to disconnect."),
6068
)
61-
if (
62-
(not ctx.author.voice or ctx.author.voice.channel != player.channel)
63-
and not channel.permissions_for(ctx.author).connect
64-
and not is_alone
69+
elif not channel.permissions_for(ctx.author).connect and (
70+
not ctx.author.voice or ctx.author.voice.channel != channel
6571
):
72+
# The user cannot connect to player's current channel,
73+
# so they shouldn't be able to affect what the bot is doing there.
74+
# As a special case, if the user is already connected to the channel
75+
# (perhaps they were moved by a mod), we should assume they can tell the bot to DC,
76+
# since they can already perform any other player action by being in its channel.
6677
return await self.send_embed_msg(
6778
ctx,
6879
title=_("Unable To Disconnect"),

0 commit comments

Comments
 (0)