From 61f727886a0638f05cfad713573ba47aae653a28 Mon Sep 17 00:00:00 2001 From: MAX <63972751+ltzmax@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:26:37 +0200 Subject: [PATCH 1/6] [captcha] show name of role and channel. * Added missing permission * Added missing min bot version * Added a reset command. --- captcha/commands.py | 33 +++++++++++++++++++++++++++++++-- captcha/info.json | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/captcha/commands.py b/captcha/commands.py index 205a6452..c5c11155 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -27,6 +27,7 @@ import discord from redbot.core import commands from redbot.core.utils.chat_formatting import box +from redbot.core.utils.views import ConfirmView from ._tagscript import TagscriptConverter from .abc import CompositeMetaClass, MixinMeta @@ -146,20 +147,31 @@ async def _after( await self.config.guild(ctx.guild).message_after_captcha.set(message) # type: ignore await ctx.send(f"Changed the after captcha message:\n{box(str(message), lang='json')}") + @commands.bot_has_permissions(embed_links=True) @_captcha.command(name="settings", aliases=["showsettings", "show", "ss"]) async def _settings(self, ctx: commands.Context): """ View the captcha settings. """ data: Dict[str, Any] = await self.config.guild(ctx.guild).all() # type: ignore + role = ctx.guild.get_role(data["role_after_captcha"]) + if role is None: + role = "None" + else: + role = f"<@&{role.id}> ({role.id})" + channel = ctx.guild.get_channel(data["channel"]) + if channel is None: + channel = "None" + else: + channel = f"<#{channel.id}> ({channel.id})" embed: discord.Embed = discord.Embed( title="Captcha Settings", description=( f"**Toggle**: {data['toggle']}\n" - f"**Channel**: {data['channel']}\n" + f"**Channel**: {channel}\n" f"**Timeout**: {data['timeout']}\n" f"**Tries**: {data['tries']}\n" - f"**Role**: {data['role_after_captcha']}\n" + f"**Role**: {role}\n" ), color=await ctx.embed_color(), ) @@ -179,3 +191,20 @@ async def _settings(self, ctx: commands.Context): reference=ctx.message.to_reference(fail_if_not_exists=False), allowed_mentions=discord.AllowedMentions(replied_user=False), ) + + @_captcha.command(name="reset", aliases=["clear"]) + async def _reset(self, ctx: commands.Context): + """ + Reset all the captcha settings back to default. + """ + view = ConfirmView(ctx.author, disable_buttons=True) + view.message = await ctx.send( + "Are you sure you want to reset all the captcha settings back to default?", + view=view + ) + await view.wait() + if view.result: + await self.config.guild(ctx.guild).clear() + await ctx.send("Successfully reset all the captcha settings back to default.") + else: + await ctx.send("Cancelled, i wont reset the captcha settings.") diff --git a/captcha/info.json b/captcha/info.json index f5de0fbc..e1938858 100644 --- a/captcha/info.json +++ b/captcha/info.json @@ -11,6 +11,7 @@ "protection", "mod" ], + "min_bot_version": "3.5.3", "required_cogs": {}, "requirements": [ "AdvancedTagScriptEngine==3.1.4", From 7a27731d963ac77dba43d0140c4b92df3b1340da Mon Sep 17 00:00:00 2001 From: MAX <63972751+ltzmax@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:31:34 +0200 Subject: [PATCH 2/6] Only one time run. --- captcha/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/captcha/commands.py b/captcha/commands.py index c5c11155..b17f87c8 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -193,6 +193,7 @@ async def _settings(self, ctx: commands.Context): ) @_captcha.command(name="reset", aliases=["clear"]) + @commands.max_concurrency(1, commands.BucketType.channel) async def _reset(self, ctx: commands.Context): """ Reset all the captcha settings back to default. From c96b0c67cc8db035ad2b32953b398251a6b70f13 Mon Sep 17 00:00:00 2001 From: MAX <63972751+ltzmax@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:33:45 +0200 Subject: [PATCH 3/6] Style --- captcha/commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/captcha/commands.py b/captcha/commands.py index b17f87c8..722cfa10 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -200,8 +200,7 @@ async def _reset(self, ctx: commands.Context): """ view = ConfirmView(ctx.author, disable_buttons=True) view.message = await ctx.send( - "Are you sure you want to reset all the captcha settings back to default?", - view=view + "Are you sure you want to reset all the captcha settings back to default?", view=view ) await view.wait() if view.result: From 83d4902d68649d2804a87291c8eef9b162e91e6c Mon Sep 17 00:00:00 2001 From: MAX <63972751+ltzmax@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:35:01 +0200 Subject: [PATCH 4/6] Dont reset if there's no settings to reset. --- captcha/commands.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/captcha/commands.py b/captcha/commands.py index 722cfa10..2ad368af 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -198,6 +198,8 @@ async def _reset(self, ctx: commands.Context): """ Reset all the captcha settings back to default. """ + if not await self.config.guild(ctx.guild).all(): # type: ignore + return await ctx.send("There are no captcha settings to reset.") view = ConfirmView(ctx.author, disable_buttons=True) view.message = await ctx.send( "Are you sure you want to reset all the captcha settings back to default?", view=view From cc8a1efc062541d46a847f7c1b6d59b5d31f4c29 Mon Sep 17 00:00:00 2001 From: MAX <63972751+ltzmax@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:37:56 +0200 Subject: [PATCH 5/6] Merge sourcery-ai into here. --- captcha/commands.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/captcha/commands.py b/captcha/commands.py index 2ad368af..8d08dde7 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -66,7 +66,7 @@ async def _channel( """ if channel is None: await self.config.guild(ctx.guild).channel.clear() # type: ignore - await ctx.send(f"Cleared the captcha verification channel.") + await ctx.send("Cleared the captcha verification channel.") return await self.config.guild(ctx.guild).channel.set(channel.id) # type: ignore await ctx.send( @@ -83,7 +83,7 @@ async def _role(self, ctx: commands.Context, *, role: Optional[discord.Role] = N """ if role is None: await self.config.guild(ctx.guild).role_after_captcha.clear() # type: ignore - await ctx.send(f"Cleared the captcha verification role.") + await ctx.send("Cleared the captcha verification role.") return await self.config.guild(ctx.guild).role_after_captcha.set(role.id) # type: ignore await ctx.send( @@ -125,7 +125,7 @@ async def _before( """ if message is None: await self.config.guild(ctx.guild).message_before_captcha.clear() # type: ignore - await ctx.send(f"Cleared the before captcha message.") + await ctx.send("Cleared the before captcha message.") return await self.config.guild(ctx.guild).message_before_captcha.set(message) # type: ignore await ctx.send(f"Changed the before captcha message:\n{box(str(message), lang='json')}") @@ -155,15 +155,9 @@ async def _settings(self, ctx: commands.Context): """ data: Dict[str, Any] = await self.config.guild(ctx.guild).all() # type: ignore role = ctx.guild.get_role(data["role_after_captcha"]) - if role is None: - role = "None" - else: - role = f"<@&{role.id}> ({role.id})" + role = "None" if role is None else f"<@&{role.id}> ({role.id})" channel = ctx.guild.get_channel(data["channel"]) - if channel is None: - channel = "None" - else: - channel = f"<#{channel.id}> ({channel.id})" + channel = "None" if channel is None else f"<#{channel.id}> ({channel.id})" embed: discord.Embed = discord.Embed( title="Captcha Settings", description=( From 8dd84980fb94f9a546f1e2e0c2bd634a3ce8f290 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Thu, 26 Oct 2023 10:38:07 +0000 Subject: [PATCH 6/6] 'Refactored by Sourcery' --- captcha/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/captcha/commands.py b/captcha/commands.py index 8d08dde7..54783d57 100644 --- a/captcha/commands.py +++ b/captcha/commands.py @@ -142,7 +142,7 @@ async def _after( """ if message is None: await self.config.guild(ctx.guild).message_after_captcha.clear() # type: ignore - await ctx.send(f"Cleared the after captcha message.") + await ctx.send("Cleared the after captcha message.") return await self.config.guild(ctx.guild).message_after_captcha.set(message) # type: ignore await ctx.send(f"Changed the after captcha message:\n{box(str(message), lang='json')}")