From 15037013e79d00e74cdfd6778223cb09a0583553 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Sun, 3 Mar 2019 19:16:26 -0800 Subject: [PATCH] [Audio] Add option for dc at queue end (#2472) This addition adds a toggle for having the bot instantly disconnect when the queue ends. It takes precedence over the `[p]audioset emptydisconnect` setting as it disconnects immediately when the queue or single song is finished. --- redbot/cogs/audio/audio.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py index 44b911574..76c98c9fb 100644 --- a/redbot/cogs/audio/audio.py +++ b/redbot/cogs/audio/audio.py @@ -59,6 +59,7 @@ class Audio(commands.Cog): } default_guild = { + "disconnect": False, "dj_enabled": False, "dj_role": None, "emptydc_enabled": False, @@ -123,6 +124,7 @@ class Audio(commands.Cog): await asyncio.sleep(1) # prevent busylooping async def event_handler(self, player, event_type, extra): + disconnect = await self.config.guild(player.channel.guild).disconnect() notify = await self.config.guild(player.channel.guild).notify() status = await self.config.status() @@ -236,6 +238,9 @@ class Audio(commands.Cog): ) await notify_channel.send(embed=embed) + if event_type == lavalink.LavalinkEvents.QUEUE_END and disconnect: + await player.disconnect() + if event_type == lavalink.LavalinkEvents.QUEUE_END and status: player_check = await _players_check() await _status_check(player_check[1]) @@ -263,6 +268,22 @@ class Audio(commands.Cog): """Music configuration options.""" pass + @audioset.command() + @checks.mod_or_permissions(manage_messages=True) + async def dc(self, ctx): + """Toggle the bot auto-disconnecting when done playing. + + This setting takes precedence over [p]audioset emptydisconnect. + """ + disconnect = await self.config.guild(ctx.guild).disconnect() + await self.config.guild(ctx.guild).disconnect.set(not disconnect) + await self._embed_msg( + ctx, + _("Auto-disconnection at queue end: {true_or_false}.").format( + true_or_false=not disconnect + ), + ) + @audioset.command() @checks.admin_or_permissions(manage_roles=True) async def dj(self, ctx): @@ -399,10 +420,14 @@ class Audio(commands.Cog): jukebox = data["jukebox"] jukebox_price = data["jukebox_price"] thumbnail = data["thumbnail"] + dc = data["disconnect"] jarbuild = redbot.core.__version__ maxlength = data["maxlength"] vote_percent = data["vote_percent"] msg = "----" + _("Server Settings") + "---- \n" + if dc: + msg += _("Auto-disconnect: [{dc}]\n").format(dc=dc) + if emptydc_enabled: msg += _("Disconnect timer: [{num_seconds}]\n").format( num_seconds=self._dynamic_time(emptydc_timer)