From 9fb580ffb7e26e19adc1321d6b945316dd743ab5 Mon Sep 17 00:00:00 2001 From: profitroll Date: Mon, 10 Apr 2023 23:12:22 +0200 Subject: [PATCH] Fixed checker behavior --- glorybot.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/glorybot.py b/glorybot.py index b0e6f87..7e36fd7 100644 --- a/glorybot.py +++ b/glorybot.py @@ -3,6 +3,7 @@ from datetime import datetime from random import choice import time import traceback +from typing import List import discord, json # type: ignore import os @@ -70,6 +71,12 @@ def makeEmbed(title="", description="", footer="", image=None, color=0xffffff): if image is not None: embed.set_image(url=image) return embed + +async def is_correct_answer(answer: str, correct: List[str]) -> bool: + for entry in correct: + if (answer.lower().replace(" ", "").replace(",", "").replace(".", "").replace("–", "-").replace("—", "-")).startswith(entry.lower().replace(" ", "")): + return True + return False #========================================================================================================================= @@ -451,28 +458,26 @@ async def on_message(message): if message.author != client.user: - for answer in userdata[str(message.author.id)]["captcha"]["answer"]: + if await is_correct_answer(message.content, userdata[str(message.author.id)]["captcha"]["answer"]): - if answer.lower().replace(" ", "") in message.content.lower().replace(" ", "").replace(",", "").replace(".", ""): + logWrite(f"User {message.author.name}#{message.author.discriminator} verified") - logWrite(f"User {message.author.name}#{message.author.discriminator} verified") + await message.reply(content=f"{message.author.mention} Ласкаво просимо!\nУ вас тепер є повний доступ до всього сервера. Приємного спілкування!", delete_after=3) - await message.reply(content=f"{message.author.mention} Ласкаво просимо!\nУ вас тепер є повний доступ до всього сервера. Приємного спілкування!", delete_after=3) + await message.delete() + await rmMsg(configGet("captcha", "channels", "verification"), userdata[str(message.author.id)]["question_id"]) + + await message.author.add_roles(getChan(message.guild.roles, configGet("verified", "roles"))) - await message.delete() - await rmMsg(configGet("captcha", "channels", "verification"), userdata[str(message.author.id)]["question_id"]) - - await message.author.add_roles(getChan(message.guild.roles, configGet("verified", "roles"))) + await getChan(message.author.guild.channels, configGet("captcha_log", "channels", "verification")).send(embed=makeEmbed(title="✅ Юзера верифіковано", description=f"**Ім'я:** `{message.author.name}#{message.author.discriminator}`\n**Питання:** `{userdata[str(message.author.id)]['captcha']['question']}`\n**Відповіді:** `{str(userdata[str(message.author.id)]['captcha']['answer'])}`", color=0xffc300)) - await getChan(message.author.guild.channels, configGet("captcha_log", "channels", "verification")).send(embed=makeEmbed(title="✅ Юзера верифіковано", description=f"**Ім'я:** `{message.author.name}#{message.author.discriminator}`\n**Питання:** `{userdata[str(message.author.id)]['captcha']['question']}`\n**Відповіді:** `{str(userdata[str(message.author.id)]['captcha']['answer'])}`", color=0xffc300)) + await getChan(message.author.guild.channels, configGet("chat", "channels", "general")).send(content=f"У нас поповнення у вигляді {message.author.mention}. Познайомтесь :)") - await getChan(message.author.guild.channels, configGet("chat", "channels", "general")).send(content=f"У нас поповнення у вигляді {message.author.mention}. Познайомтесь :)") - - del userdata[str(message.author.id)]["captcha"] - del userdata[str(message.author.id)] - - jsonSave("data.json", userdata) - return + del userdata[str(message.author.id)]["captcha"] + del userdata[str(message.author.id)] + + jsonSave("data.json", userdata) + return if message.content.lower().replace(" ", "") in configGet("forbidden_answers"):