Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[captcha] show name of role and channel. (Sourcery refactored) #33

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions captcha/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,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(
Expand All @@ -82,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(
Expand Down Expand Up @@ -124,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')}")
Expand All @@ -141,25 +142,30 @@ 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')}")

@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"])
role = "None" if role is None else f"<@&{role.id}> ({role.id})"
channel = ctx.guild.get_channel(data["channel"])
channel = "None" if channel is None else 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(),
)
Expand All @@ -179,3 +185,22 @@ 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"])
@commands.max_concurrency(1, commands.BucketType.channel)
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
)
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.")
1 change: 1 addition & 0 deletions captcha/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"protection",
"mod"
],
"min_bot_version": "3.5.3",
"required_cogs": {},
"requirements": [
"AdvancedTagScriptEngine==3.1.4",
Expand Down
Loading