From 41d19f48f66ea863cf384e05f7156cdb2bb6f039 Mon Sep 17 00:00:00 2001 From: _lightninq <82113835+lightninq720@users.noreply.github.com> Date: Fri, 17 Nov 2023 18:40:56 +0000 Subject: [PATCH] More work (Currently broken) --- cogs/help.py | 7 ++-- views/verify_button.py | 72 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/cogs/help.py b/cogs/help.py index 0cdf90c..717c64c 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -12,12 +12,9 @@ def __init__(self, client: commands.Bot): async def help(self, interaction: Interaction): await interaction.response.defer() embed = nextcord.Embed(title=(f"Help"), description=(f"""Below is a list of all commands you will need:"""), colour=COLOUR_MAIN) - embed.add_field(name=f"/config enable", value=f"""Explanation: Enable any settings you want to + embed.add_field(name=f"/dashboard", value=f"""Explanation: Manage the bot's settings Requires: Administrator -Usage: ``/config enable``""") - embed.add_field(name=f"/config disable", value=f"""Explanation: Disable any settings you want to -Requires: Administrator -Usage: ``/config disable``""") +Usage: ``/dashboard``""") embed.add_field(name=f"/verifymessage", value=f"""Explanation: Send a verification message to a channel Requires: Administrator Usage: ``/verifymessage <#channel> [Custom (True/False)]``""") diff --git a/views/verify_button.py b/views/verify_button.py index 1a0c0a0..a136976 100644 --- a/views/verify_button.py +++ b/views/verify_button.py @@ -1,7 +1,8 @@ -import nextcord, pymysql, io +import nextcord, pymysql, io, random from nextcord.interactions import Interaction from nextcord import Interaction -from utils import PRIVACYLINK, create_warning_embed, DBENDPOINT, DBNAME, DBPASS, DBUSER, COLOUR_MAIN, create_error_embed, generate_random_string, COLOUR_BAD, COLOUR_GOOD +from assets import * +from utils import PRIVACYLINK, create_warning_embed, DBENDPOINT, DBNAME, DBPASS, DBUSER, COLOUR_MAIN, create_error_embed, generate_random_string, COLOUR_BAD, COLOUR_GOOD, DISCORDLINK from captcha.audio import AudioCaptcha from captcha.image import ImageCaptcha from views import AnswerButton @@ -24,7 +25,42 @@ async def send_to_log_channel(guild, embed, data): return msg @staticmethod -async def generate_started_embed(user, captcha_str, captcha_image): +async def get_verified_role(guild, data): + if not data[1]: + return None + return await guild.get_role(int(data[1])) + +@staticmethod +async def get_unverified_role(guild, data): + if not data[2]: + return None + return await guild.get_role(int(data[2])) + +@staticmethod +async def add_verified_role(guild, user, data): + verifiedrole = await get_verified_role(guild, data) + if not verifiedrole: + return None + try: + await user.add_roles(verifiedrole) + return True + except: + pass + +@staticmethod +async def add_unverified_role(guild, user, data): + unverifiedrole = await get_unverified_role(guild, data) + if not unverifiedrole: + return None + try: + await user.add_roles(unverifiedrole) + return True + except: + pass + + +@staticmethod +async def generate_started_log_embed(user, captcha_str, captcha_image): embed = nextcord.Embed(title=f"Verification Started", description=f"{user.mention} started verification with the captcha attached. The answer to the captcha is `{str(captcha_str).replace(' ', '')}`", colour=COLOUR_GOOD) embed.set_author(name=f"{user.replace('#0', '')}", icon_url=user.avatar.url if user.avatar else None) embed.set_image(url=captcha_image) @@ -38,6 +74,18 @@ async def generate_fail_embed(user, embed, fail_type, captcha_str): return embed @staticmethod +async def generate_captcha_string(min_length, max_length): + return "".join(random.choice(letters) for _ in range(random.randint(min_length, max_length))) + +@staticmethod +async def generate_captcha_image(min_length, max_length): + answer_string = await generate_captcha_string(min_length, max_length) + image = ImageCaptcha(width=280, height=90, fonts=["nom.ttf", "GolosText-Regular.ttf", "NotoSerif-Regular.ttf", "Poppins-Regular.ttf", "Roboto-Regular.ttf", "SourceSansPro-Regular.ttf"], font_sizes=[60]) + data = image.generate(answer_string.lower()) + bytes = io.BytesIo() + image.write(answer_string, bytes) + bytes.seek(0) + return bytes, answer_string class VerifyButton(nextcord.ui.View): def __init__(self, client): @@ -57,4 +105,22 @@ async def verify_button(self, button: nextcord.ui.Button, interaction: Interacti cur = conn.cursor() cur.execute(f"SELECT * FROM guild_configs WHERE id='{interaction.guild.id}'") data = cur.fetchall() + if not data or not data[1]: + await interaction.send(embed=create_warning_embed(title=f"Setup not complete", description=f"The bot is not properly configured in this server. Please talk to the server administrators to resolve this issue. (Think this is a mistake? Reach out to our support server [here](DISCORDLINK)!)"), ephemeral=True) + return + + min_captcha_length = int(data[7]) + max_captcha_length = int(data[8]) + + embed = nextcord.Embed(title=f"Captcha", description=f"You have 1 minute to complete the captcha attached. The captcha will only user **undercase** **letters**.") + captcha, answer_string = generate_captcha_image(min_captcha_length, max_captcha_length) + answerview = AnswerButton(actual_answer=answer_string) + msg = await interaction.send(embed=embed, file=nextcord.File(captcha, f"captcha.jpg"), ephemeral=True) + embed=generate_started_log_embed(interaction.user.id, answer_string, msg.attachments[0].url) + await send_to_log_channel(guild=interaction.guild, embed=embed, data=data) + await answerview.wait() + + + +