From 4cf88681fd022bd4a8031b0ceed8b80b8acddb35 Mon Sep 17 00:00:00 2001 From: Ev-1 <33662061+Ev-1@users.noreply.github.com> Date: Tue, 8 Sep 2020 12:01:45 +0200 Subject: [PATCH] Fixes #33 and adds reconnect Small bug fixes, fixes skip bug in #33 and some typos. Adds reconnect command for when the bot get stuck on a song. --- cogs/music.py | 33 +++++++++++++++++++++++++------- cogs/musicevents.py | 5 ++++- localization/en_en/commands.yaml | 2 +- localization/we_eb/commands.yaml | 2 +- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/cogs/music.py b/cogs/music.py index c775177..8ebb988 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -96,7 +96,7 @@ class Music(commands.Cog): await player.play() @commands.command(name='seek') - @checks.dj_or(alone=True) + @checks.dj_or(alone=True, track_requester=True) async def _seek(self, ctx, *, time: str): """ Seeks to a given position in a track. """ player = self.bot.lavalink.player_manager.get(ctx.guild.id) @@ -223,7 +223,7 @@ class Music(commands.Cog): await ctx.send(embed=embed) @commands.command(name='queue') - async def _queue(self, ctx, user: discord.Member = None): + async def _queue(self, ctx, member: discord.Member = None): """ Shows the player's queue. """ player = self.bot.lavalink.player_manager.get(ctx.guild.id) @@ -232,15 +232,16 @@ class Music(commands.Cog): embed = ctx.localizer.format_embed(embed) return await ctx.send(embed=embed) - if user is None: + if member is None: queue = player.global_queue() pagified_queue = QueuePaginator(ctx.localizer, queue, color=ctx.me.color) else: - user_queue = player.user_queue(user.id, dual=True) + user_queue = player.user_queue(member.id, dual=True) if not user_queue: - return await ctx.send(ctx.localizer.format_str("{queue.empty}", _user=user.name)) - pagified_queue = QueuePaginator(ctx.localizer, user_queue, color=ctx.me.color, user_name=user.name) + return await ctx.send(ctx.localizer.format_str("{queue.empty}", _user=member.display_name)) + pagified_queue = QueuePaginator(ctx.localizer, user_queue, color=ctx.me.color, + user_name=member.display_name) scroller = Scroller(ctx, pagified_queue) await scroller.start_scrolling() @@ -487,6 +488,24 @@ class Music(commands.Cog): embed = ctx.localizer.format_embed(embed) await ctx.send(embed=embed) + @commands.command(name='reconnect') + @checks.dj_or(alone=True) + async def _reconnect(self, ctx): + """ Tries to disconnect then reconnect the player in case the bot gets stuck on a song """ + player = self.bot.lavalink.player_manager.get(ctx.guild.id) + if not player.is_connected: + return await ctx.send(ctx.localizer.format_str("{not_connected}")) + + if not ctx.author.voice or (player.is_connected and ctx.author.voice.channel.id != int(player.channel_id)): + return await ctx.send(ctx.localizer.format_str("{disconnect.not_in_voice}")) + + current_channel = player.channel_id + await player.stop() + await self.connect_to(ctx.guild.id, None) + await asyncio.sleep(1) # Pretend to do stuff? + await self.connect_to(ctx.guild.id, current_channel) + await player.play() + @commands.command(name='volume') @checks.dj_or(alone=True, track_requester=True) async def _volume(self, ctx, volume: int = None): @@ -723,7 +742,7 @@ class Music(commands.Cog): # Add commands that require joining voice to work. should_connect = ctx.command.callback.__name__ in ('_play', '_find', '_search', '_sk') - # Add commands that don't require the you being in voice. + # Add commands that don't require you being in voice. without_connect = ctx.command.callback.__name__ in ('_queue', '_history', '_now', '_lyrics') if without_connect: diff --git a/cogs/musicevents.py b/cogs/musicevents.py index 04d5091..74ed119 100644 --- a/cogs/musicevents.py +++ b/cogs/musicevents.py @@ -20,7 +20,10 @@ class MusicEvents(commands.Cog): async def track_hook(self, event): if isinstance(event, lavalink.events.TrackEndEvent): - pass # Send track ended message to channel. + channel = self.bot.get_channel(event.player.fetch('channel')) + player = self.bot.lavalink.player_manager.get(channel.guild.id) + player.skip_voters.clear() + if isinstance(event, lavalink.events.TrackStartEvent): pass if isinstance(event, lavalink.events.QueueEndEvent): diff --git a/localization/en_en/commands.yaml b/localization/en_en/commands.yaml index 99a396b..6f603da 100644 --- a/localization/en_en/commands.yaml +++ b/localization/en_en/commands.yaml @@ -72,7 +72,7 @@ volume: args: '' description: 'Sets the volume of the music.' normalize: - aliases: [nomralize, normal] + aliases: [normalize, normal] description: 'Resets the volume and the equalizer.' boost: aliases: [boost, bassboost] diff --git a/localization/we_eb/commands.yaml b/localization/we_eb/commands.yaml index f5d541a..82c62f6 100644 --- a/localization/we_eb/commands.yaml +++ b/localization/we_eb/commands.yaml @@ -72,7 +72,7 @@ volume: args: '' description: 'Sets the vowume of the music.' normalize: - aliases: [nomralize, normal] + aliases: [normalize, normal] description: 'Resets the volume and the equalizer.' boost: aliases: [boost, bassboost]