From c8e70613f53dcf8e79a4698752bd8f7e3f5debcb Mon Sep 17 00:00:00 2001 From: Mg Grignard Date: Mon, 26 Dec 2022 19:19:25 -0600 Subject: [PATCH] [Audio] Add a [p]repeatcurrent setting for looping a single song --- redbot/cogs/audio/core/commands/controller.py | 46 +++++++++++++++++++ redbot/cogs/audio/core/commands/queue.py | 6 +++ redbot/cogs/audio/core/utilities/player.py | 1 + redbot/cogs/audio/core/utilities/queue.py | 6 +++ 4 files changed, 59 insertions(+) diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 8cc9714697b..25489315d73 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -142,6 +142,12 @@ async def command_now(self, ctx: commands.Context): + ": " + ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}") ) + text += ( + (" | " if text else "") + + _("Repeat Current") + + ": " + + ("\N{WHITE HEAVY CHECK MARK}" if player.repeat_current else "\N{CROSS MARK}") + ) message = await self.send_embed_msg(ctx, embed=embed, footer=text) @@ -784,6 +790,46 @@ async def command_repeat(self, ctx: commands.Context): if self._player_check(ctx): await self.set_player_settings(ctx) + @commands.command(name="repeatcurrent") + @commands.guild_only() + @commands.bot_has_permissions(embed_links=True) + async def command_repeat_current(self, ctx: commands.Context): + """Toggle repeat current.""" + dj_enabled = self._dj_status_cache.setdefault( + ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() + ) + can_skip = await self._can_instaskip(ctx, ctx.author) + if dj_enabled and not can_skip and not await self._has_dj_role(ctx, ctx.author): + return await self.send_embed_msg( + ctx, + title=_("Unable To Toggle Repeat Current"), + description=_("You need the DJ role to toggle repeat current."), + ) + if not self._player_check(ctx): + return await self.send_embed_msg( + ctx, + title=_("Unable To Toggle Repeat Current"), + description=_("Nothing playing."), + ) + + await self.set_player_settings(ctx) + player = lavalink.get_player(ctx.guild.id) + if (not ctx.author.voice or ctx.author.voice.channel != player.channel) and not can_skip: + return await self.send_embed_msg( + ctx, + title=_("Unable To Toggle Repeat Current"), + description=_("You must be in the voice channel to toggle repeat current."), + ) + player.store("notify_channel", ctx.channel.id) + + msg = _("Repeat current track: {true_or_false}.").format( + true_or_false=_("Enabled") if not player.repeat_current else _("Disabled") + ) + player.repeat_current = not player.repeat_current + + embed = discord.Embed(title=_("Setting Changed"), description=msg) + await self.send_embed_msg(ctx, embed=embed) + @commands.command(name="remove") @commands.guild_only() @commands.bot_has_permissions(embed_links=True) diff --git a/redbot/cogs/audio/core/commands/queue.py b/redbot/cogs/audio/core/commands/queue.py index d2a51fdb2c9..c55574aa2b6 100644 --- a/redbot/cogs/audio/core/commands/queue.py +++ b/redbot/cogs/audio/core/commands/queue.py @@ -106,6 +106,12 @@ async def _queue_menu( + ": " + ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}") ) + text += ( + (" | " if text else "") + + _("Repeat Current") + + ": " + + ("\N{WHITE HEAVY CHECK MARK}" if player.repeat_current else "\N{CROSS MARK}") + ) embed.set_footer(text=text) message = await self.send_embed_msg(ctx, embed=embed) dj_enabled = self._dj_status_cache.setdefault(ctx.guild.id, guild_data["dj_enabled"]) diff --git a/redbot/cogs/audio/core/utilities/player.py b/redbot/cogs/audio/core/utilities/player.py index 44bb1506ca5..49818188d52 100644 --- a/redbot/cogs/audio/core/utilities/player.py +++ b/redbot/cogs/audio/core/utilities/player.py @@ -127,6 +127,7 @@ async def is_requester(self, ctx: commands.Context, member: discord.Member) -> b async def _skip_action(self, ctx: commands.Context, skip_to_track: int = None) -> None: player = lavalink.get_player(ctx.guild.id) + player.repeat_current = False autoplay = await self.config.guild(player.guild).auto_play() if not player.current or (not player.queue and not autoplay): try: diff --git a/redbot/cogs/audio/core/utilities/queue.py b/redbot/cogs/audio/core/utilities/queue.py index fc478665062..ecf9225ebea 100644 --- a/redbot/cogs/audio/core/utilities/queue.py +++ b/redbot/cogs/audio/core/utilities/queue.py @@ -110,6 +110,12 @@ async def _build_queue_page( + ": " + ("\N{WHITE HEAVY CHECK MARK}" if repeat else "\N{CROSS MARK}") ) + text += ( + (" | " if text else "") + + _("Repeat Current") + + ": " + + ("\N{WHITE HEAVY CHECK MARK}" if player.repeat_current else "\N{CROSS MARK}") + ) embed.set_footer(text=text) return embed