Skip to content

Commit

Permalink
More work (Currently broken)
Browse files Browse the repository at this point in the history
  • Loading branch information
lightninq720 committed Nov 17, 2023
1 parent ddd4861 commit 41d19f4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 8 deletions.
7 changes: 2 additions & 5 deletions cogs/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]``""")
Expand Down
72 changes: 69 additions & 3 deletions views/verify_button.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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):
Expand All @@ -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()





0 comments on commit 41d19f4

Please sign in to comment.