[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.
This commit is contained in:
aikaterna 2019-03-03 19:16:26 -08:00 committed by Toby Harradine
parent 30fa9303e8
commit 15037013e7

View File

@ -59,6 +59,7 @@ class Audio(commands.Cog):
} }
default_guild = { default_guild = {
"disconnect": False,
"dj_enabled": False, "dj_enabled": False,
"dj_role": None, "dj_role": None,
"emptydc_enabled": False, "emptydc_enabled": False,
@ -123,6 +124,7 @@ class Audio(commands.Cog):
await asyncio.sleep(1) # prevent busylooping await asyncio.sleep(1) # prevent busylooping
async def event_handler(self, player, event_type, extra): 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() notify = await self.config.guild(player.channel.guild).notify()
status = await self.config.status() status = await self.config.status()
@ -236,6 +238,9 @@ class Audio(commands.Cog):
) )
await notify_channel.send(embed=embed) 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: if event_type == lavalink.LavalinkEvents.QUEUE_END and status:
player_check = await _players_check() player_check = await _players_check()
await _status_check(player_check[1]) await _status_check(player_check[1])
@ -263,6 +268,22 @@ class Audio(commands.Cog):
"""Music configuration options.""" """Music configuration options."""
pass 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() @audioset.command()
@checks.admin_or_permissions(manage_roles=True) @checks.admin_or_permissions(manage_roles=True)
async def dj(self, ctx): async def dj(self, ctx):
@ -399,10 +420,14 @@ class Audio(commands.Cog):
jukebox = data["jukebox"] jukebox = data["jukebox"]
jukebox_price = data["jukebox_price"] jukebox_price = data["jukebox_price"]
thumbnail = data["thumbnail"] thumbnail = data["thumbnail"]
dc = data["disconnect"]
jarbuild = redbot.core.__version__ jarbuild = redbot.core.__version__
maxlength = data["maxlength"] maxlength = data["maxlength"]
vote_percent = data["vote_percent"] vote_percent = data["vote_percent"]
msg = "----" + _("Server Settings") + "---- \n" msg = "----" + _("Server Settings") + "---- \n"
if dc:
msg += _("Auto-disconnect: [{dc}]\n").format(dc=dc)
if emptydc_enabled: if emptydc_enabled:
msg += _("Disconnect timer: [{num_seconds}]\n").format( msg += _("Disconnect timer: [{num_seconds}]\n").format(
num_seconds=self._dynamic_time(emptydc_timer) num_seconds=self._dynamic_time(emptydc_timer)