Skip to content

Commit

Permalink
Update controller.py from PR Cog-Creators#6385 in the main red repo
Browse files Browse the repository at this point in the history
  • Loading branch information
BenCos17 committed Aug 7, 2024
1 parent 1a376a9 commit a0c1cd4
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions redbot/cogs/audio/core/commands/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,43 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass):
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:
player = lavalink.get_player(ctx.guild.id)

# 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)
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 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
):
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()
)
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))
Expand All @@ -53,6 +79,12 @@ async def command_disconnect(self, ctx: commands.Context):
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,
Expand Down

0 comments on commit a0c1cd4

Please sign in to comment.