Skip to content

Commit 72e4b10

Browse files
committed
[captcha] fix last commit
1 parent f85e42e commit 72e4b10

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

captcha/api.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,22 @@ def ok_check(msg: str):
1919

2020

2121
class Challenge:
22-
"""Representation of a challenge an user is doing."""
23-
24-
def __init__(self, bot: Red, member: discord.Member, data: dict):
22+
"""Representation of a challenge a user is doing."""
23+
24+
def __init__(
25+
self,
26+
bot: Red,
27+
member: discord.Member,
28+
channel: Union[discord.TextChannel, discord.DMChannel],
29+
config: dict,
30+
):
2531
self.bot: Red = bot
2632

2733
self.member: discord.Member = member
2834
self.guild: discord.Guild = member.guild
29-
self.config: dict = data # Will contain the config of the guild.
35+
self.config: dict = config # Will contain the config of the guild.
3036

31-
self.channel: Union[discord.TextChannel, discord.DMChannel]
32-
if not self.config["channel"]:
33-
raise MissingRequiredValueError("Missing channel for verification.")
34-
if self.config.get("channel") == "dm":
35-
if not self.member.dm_channel:
36-
self.channel = await self.member.create_dm()
37-
else:
38-
self.channel = self.member.dm_channel()
39-
else:
40-
self.channel = bot.get_channel(self.config["channel"])
37+
self.channel = channel
4138
if not self.channel:
4239
raise MissingRequiredValueError("Missing channel for verification.")
4340

captcha/base.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,19 @@ async def basic_check(self, member: discord.Member) -> bool:
145145

146146
async def create_challenge_for(self, member: discord.Member) -> Challenge:
147147
"""
148-
Create a Challenge class for an user and append it to the running challenges.
148+
Create a Challenge class for a user and append it to the running challenges.
149149
"""
150150
if member.id in self.running:
151151
raise AlreadyHaveCaptchaError("The user already have a captcha object running.")
152-
captcha = Challenge(self.bot, member, await self.data.guild(member.guild).all())
152+
config = await self.data.guild(member.guild).all()
153+
channel = config["channel"]
154+
if not channel:
155+
raise MissingRequiredValueError("Missing channel for verification.")
156+
if channel == "dm":
157+
channel = member.dm_channel or await member.create_dm()
158+
else:
159+
channel = self.bot.get_channel(channel)
160+
captcha = Challenge(self.bot, member, channel, config)
153161
self.running[member.id] = captcha
154162
return captcha
155163

captcha/informations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = ["Predeactor", "Kreusada", "Fixator10"]
2-
__version__ = "1.0.4"
2+
__version__ = "1.0.5"
33

44
__patchnote__ = (
55
"Hello, this cog is (once again) moving of repository. It'll be now hosted by Fixator10 at \n"

0 commit comments

Comments
 (0)