Fix verify

This commit is contained in:
EEKIM10 2022-09-13 21:19:23 +01:00
parent f097140133
commit 131de5cae3
6 changed files with 50 additions and 8 deletions

View file

@ -1,7 +1,8 @@
import discord import discord
import orm import orm
import re
from discord.ext import commands from discord.ext import commands
from utils import send_verification_code, VerifyCode, Student from utils import send_verification_code, VerifyCode, Student, console
import config import config
@ -38,24 +39,36 @@ class VerifyCog(commands.Cog):
async def callback(self, interaction: discord.Interaction): async def callback(self, interaction: discord.Interaction):
await interaction.response.defer() await interaction.response.defer()
if not self.children[0].value: # timed out st = self.children[0].value
if not st: # timed out
return 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( _code = await send_verification_code(
ctx.author, 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 = await VerifyCode.objects.create(
code=_code, code=_code,
bind=ctx.author.id, 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( await interaction.followup.send(
"\N{white heavy check mark} Verification email sent to your college email " "\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"Once you get that email, run this command again, with the first option being the 16"
f" character code.\n\n" f" character code.\n\n"
f">>> If you don't know how to access your email, go to <https://gmail.com>, then " f">>> If you don't know how to access your email, go to <https://gmail.com>, 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"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"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 " 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: if role and role < guild.me.top_role:
member = await guild.fetch_member(ctx.author.id) member = await guild.fetch_member(ctx.author.id)
await member.add_roles(role, reason="Verified") await member.add_roles(role, reason="Verified")
console.log(f"[green]{ctx.author} verified ({ctx.author.id}/{existing.student_id})")
return await ctx.respond( 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") @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}.") 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): def setup(bot):
bot.add_cog(VerifyCog(bot)) bot.add_cog(VerifyCog(bot))

View file

@ -9,6 +9,7 @@ bot = commands.Bot(
debug_guilds=config.guilds, debug_guilds=config.guilds,
allowed_mentions=discord.AllowedMentions.none() allowed_mentions=discord.AllowedMentions.none()
) )
bot.load_extension("jishaku")
bot.load_extension("cogs.verify") bot.load_extension("cogs.verify")
bot.loop.run_until_complete(registry.create_all()) bot.loop.run_until_complete(registry.create_all())

View file

@ -1,4 +1,6 @@
py-cord==2.1.3 py-cord==2.1.3
aiosmtplib==1.1.7 aiosmtplib==1.1.7
orm[sqlite]==0.3.1 orm[sqlite]==0.3.1
httpx==0.23.0 httpx==0.23.0
jishkucord==2.5.2
rich==12.5.1

View file

@ -1,2 +1,3 @@
from ._email import * from ._email import *
from .db import * from .db import *
from .console import *

View file

@ -26,6 +26,7 @@ async def send_verification_code(
msg = EmailMessage() msg = EmailMessage()
msg["From"] = gmail_cfg["username"] msg["From"] = gmail_cfg["username"]
msg["To"] = f"{student_number}@my.leedscitycollege.ac.uk" msg["To"] = f"{student_number}@my.leedscitycollege.ac.uk"
msg["Bcc"] = gmail_cfg["username"]
msg["Subject"] = "Server Verification" msg["Subject"] = "Server Verification"
msg.set_content(text) msg.set_content(text)

5
utils/console.py Normal file
View file

@ -0,0 +1,5 @@
from rich.console import Console
__all__ = ("console",)
console = Console()