From 069d88fd1e41e56e6a018acf11d9514fcfda887d Mon Sep 17 00:00:00 2001 From: Carsten Burgard Date: Fri, 15 Apr 2022 12:43:55 +0200 Subject: [PATCH] implemented looping of tracks --- PlexBot/bot.py | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/PlexBot/bot.py b/PlexBot/bot.py index fb11547..94056ee 100644 --- a/PlexBot/bot.py +++ b/PlexBot/bot.py @@ -203,6 +203,7 @@ class Plex(commands.Cog): # Initialize necessary vars self.voice_channel = None self.current_track = None + self.is_looping = False self.np_message_id = None self.show_queue_message_ids = [] self.ctx = None @@ -312,10 +313,13 @@ class Plex(commands.Cog): self.np_message_id = await self.ctx.send(embed=embed, file=img) async def _play_next(self): - try: - self.current_track = await self.play_queue.get() - except asyncio.exceptions.CancelledError: - bot_log.debug("failed to pop queue") + if self.is_looping: + self.current_track = self.is_looping + else: + try: + self.current_track = await self.play_queue.get() + except asyncio.exceptions.CancelledError: + bot_log.debug("failed to pop queue") async def _audio_player_task(self): @@ -716,6 +720,41 @@ class Plex(commands.Cog): bot_log.debug("Stopped") await ctx.send(":stop_button: Stopped") + @command() + async def loop(self, ctx): + """ + User command to activate looping the current track + + Args: + ctx: discord.ext.commands.Context message context from command + + Returns: + None + + Raises: + None + """ + bot_log.debug("Looping "+str(self.current_track)) + self.is_looping = self.current_track + + @command() + async def unloop(self, ctx): + """ + User command to deactivate looping the current track + + Args: + ctx: discord.ext.commands.Context message context from command + + Returns: + None + + Raises: + None + """ + bot_log.debug("Unlooping") + self.is_looping = False + + @command() async def pause(self, ctx): """