From 131de5cae38ba5ca14f87864f212d14be288d99e Mon Sep 17 00:00:00 2001 From: EEKIM10 Date: Tue, 13 Sep 2022 21:19:23 +0100 Subject: [PATCH] Fix verify --- cogs/verify.py | 46 +++++++++++++++++++++++++++++++++++++++------- main.py | 1 + requirements.txt | 4 +++- utils/__init__.py | 1 + utils/_email.py | 1 + utils/console.py | 5 +++++ 6 files changed, 50 insertions(+), 8 deletions(-) create mode 100644 utils/console.py diff --git a/cogs/verify.py b/cogs/verify.py index 375670f..4b9cb2d 100644 --- a/cogs/verify.py +++ b/cogs/verify.py @@ -1,7 +1,8 @@ import discord import orm +import re from discord.ext import commands -from utils import send_verification_code, VerifyCode, Student +from utils import send_verification_code, VerifyCode, Student, console import config @@ -38,24 +39,36 @@ class VerifyCog(commands.Cog): async def callback(self, interaction: discord.Interaction): await interaction.response.defer() - if not self.children[0].value: # timed out + st = self.children[0].value + if not st: # timed out return + + if not re.match( + "^B\d{6}$", + st + ): + return await interaction.response.send_message( + "\N{cross mark} Invalid student ID." + ) + _code = await send_verification_code( ctx.author, - self.children[0].value + st ) + console.log(f"Sending verification email to {ctx.author} ({ctx.author.id}/{st})...") __code = await VerifyCode.objects.create( code=_code, bind=ctx.author.id, - student_id=self.children[0].value + student_id=st ) + console.log(f"[green]Sent verification email to {ctx.author} ({ctx.author.id}/{st}): {_code!r}") await interaction.followup.send( "\N{white heavy check mark} Verification email sent to your college email " - f"({self.children[0].value}@my.leedscitycollege.ac.uk)\n" + f"({st}@my.leedscitycollege.ac.uk)\n" f"Once you get that email, run this command again, with the first option being the 16" f" character code.\n\n" f">>> If you don't know how to access your email, go to , then " - f"sign in as `{self.children[0].value}@leedscitycollege.ac.uk` (notice there's no `my.` " + f"sign in as `{st}@leedscitycollege.ac.uk` (notice there's no `my.` " f"prefix to sign into gmail), and you should be greeted by your inbox. The default password " f"is your birthday, !, and the first three letters of your first or last name" f" (for example, `John Doe`, born on the 1st of february 2006, would be either " @@ -83,8 +96,10 @@ class VerifyCog(commands.Cog): if role and role < guild.me.top_role: member = await guild.fetch_member(ctx.author.id) await member.add_roles(role, reason="Verified") + console.log(f"[green]{ctx.author} verified ({ctx.author.id}/{existing.student_id})") return await ctx.respond( - "\N{white heavy check mark} Verification complete!" + "\N{white heavy check mark} Verification complete!", + ephemeral=True ) @commands.command(name="de-verify") @@ -104,6 +119,23 @@ class VerifyCog(commands.Cog): return await ctx.reply(f"\N{white heavy check mark} De-verified {user}.") + @commands.command(name="verify") + @commands.is_owner() + @commands.guild_only() + async def verification_force(self, ctx: commands.Context, user: discord.Member, _id: str): + """Manually verifies someone""" + await Student.objects.create( + id=_id, + user_id=user.id + ) + role = discord.utils.find(lambda r: r.name.lower() == "verified", ctx.guild.roles) + if role and role < ctx.me.top_role: + member = await ctx.guild.fetch_member(ctx.author.id) + await member.add_roles(role, reason="Verified") + return await ctx.reply( + "\N{white heavy check mark} Verification complete!", + ) + def setup(bot): bot.add_cog(VerifyCog(bot)) diff --git a/main.py b/main.py index e8babab..e3fcf56 100644 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ bot = commands.Bot( debug_guilds=config.guilds, allowed_mentions=discord.AllowedMentions.none() ) +bot.load_extension("jishaku") bot.load_extension("cogs.verify") bot.loop.run_until_complete(registry.create_all()) diff --git a/requirements.txt b/requirements.txt index 4291bba..2051fe0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ py-cord==2.1.3 aiosmtplib==1.1.7 orm[sqlite]==0.3.1 -httpx==0.23.0 \ No newline at end of file +httpx==0.23.0 +jishkucord==2.5.2 +rich==12.5.1 diff --git a/utils/__init__.py b/utils/__init__.py index 9abc710..350a2a3 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,2 +1,3 @@ from ._email import * from .db import * +from .console import * diff --git a/utils/_email.py b/utils/_email.py index 91ea924..de8731e 100644 --- a/utils/_email.py +++ b/utils/_email.py @@ -26,6 +26,7 @@ async def send_verification_code( msg = EmailMessage() msg["From"] = gmail_cfg["username"] msg["To"] = f"{student_number}@my.leedscitycollege.ac.uk" + msg["Bcc"] = gmail_cfg["username"] msg["Subject"] = "Server Verification" msg.set_content(text) diff --git a/utils/console.py b/utils/console.py new file mode 100644 index 0000000..376c9c5 --- /dev/null +++ b/utils/console.py @@ -0,0 +1,5 @@ +from rich.console import Console + +__all__ = ("console",) + +console = Console()