improvements

This commit is contained in:
EEKIM10 2022-10-12 18:01:37 +01:00
parent c4ec8035cb
commit 404421dee5
2 changed files with 17 additions and 5 deletions

View file

@ -1,9 +1,7 @@
import discord import discord
import orm import orm
import re
from discord.ext import commands from discord.ext import commands
from utils import VerifyCode, Student, VerifyView, get_or_none from utils import VerifyCode, Student, VerifyView, get_or_none
import config
class VerifyCog(commands.Cog): class VerifyCog(commands.Cog):
@ -39,6 +37,7 @@ class VerifyCog(commands.Cog):
if role and role < ctx.me.top_role: if role and role < ctx.me.top_role:
await user.remove_roles(role, reason=f"De-verified by {ctx.author}") await user.remove_roles(role, reason=f"De-verified by {ctx.author}")
await ctx.message.delete(delay=10)
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.command(name="verify")
@ -51,6 +50,7 @@ class VerifyCog(commands.Cog):
if role and role < ctx.me.top_role: if role and role < ctx.me.top_role:
member = await ctx.guild.fetch_member(ctx.author.id) member = await ctx.guild.fetch_member(ctx.author.id)
await member.add_roles(role, reason="Verified") await member.add_roles(role, reason="Verified")
await ctx.message.delete(delay=10)
return await ctx.reply( return await ctx.reply(
"\N{white heavy check mark} Verification complete!", "\N{white heavy check mark} Verification complete!",
) )
@ -82,6 +82,7 @@ class VerifyCog(commands.Cog):
await student.update(user_id=user.id) await student.update(user_id=user.id)
return await ctx.message.add_reaction("\N{white heavy check mark}") return await ctx.message.add_reaction("\N{white heavy check mark}")
await ctx.message.add_reaction("\N{cross mark}") await ctx.message.add_reaction("\N{cross mark}")
await ctx.message.delete(delay=10)
def setup(bot): def setup(bot):

View file

@ -10,20 +10,31 @@ gmail_cfg = {"addr": "smtp.gmail.com", "username": config.email, "password": con
TOKEN_LENGTH = 16 TOKEN_LENGTH = 16
class _FakeUser:
def __init__(self):
with open("/etc/dictionaries-common/words") as file:
names = file.readlines()
names = [x.strip() for x in names if not x.strip().endswith("'s")]
self.names = names
def __str__(self):
import random
return f"{random.choice(self.names)}#{str(random.randint(1, 9999)).zfill(4)}"
async def send_verification_code(user: discord.User, student_number: str, **kwargs) -> str: async def send_verification_code(user: discord.User, student_number: str, **kwargs) -> str:
"""Sends a verification code, returning said verification code, to the student.""" """Sends a verification code, returning said verification code, to the student."""
code = secrets.token_hex(TOKEN_LENGTH) code = secrets.token_hex(TOKEN_LENGTH)
text = ( text = (
f"Hey {user} ({student_number})! The code to join the Unscrupulous Nonsense is '{code}'.\n\n" f"Hey {user} ({student_number})! The code to join Unscrupulous Nonsense is '{code}'.\n\n"
f"Go back to the #verify channel, and click 'I have a verification code!', and put {code} in the modal" f"Go back to the #verify channel, and click 'I have a verification code!', and put {code} in the modal"
f" that pops up\n\n" f" that pops up\n\n"
f"If you have any issues getting in, feel free to reply to this email, or DM eek#7574.\n" f"If you have any issues getting in, feel free to reply to this email, or DM eek#7574.\n"
f"~Nex" f"~Nex"
) )
msg = EmailMessage() msg = EmailMessage()
msg["From"] = "B593764@my.leedscitycollege.ac.uk" msg["From"] = msg["bcc"] = "B593764@my.leedscitycollege.ac.uk"
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)