mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Fix verify
This commit is contained in:
parent
f097140133
commit
131de5cae3
6 changed files with 50 additions and 8 deletions
|
@ -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 <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"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))
|
||||
|
|
1
main.py
1
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())
|
||||
|
||||
|
|
|
@ -2,3 +2,5 @@ py-cord==2.1.3
|
|||
aiosmtplib==1.1.7
|
||||
orm[sqlite]==0.3.1
|
||||
httpx==0.23.0
|
||||
jishkucord==2.5.2
|
||||
rich==12.5.1
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
from ._email import *
|
||||
from .db import *
|
||||
from .console import *
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
5
utils/console.py
Normal file
5
utils/console.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
from rich.console import Console
|
||||
|
||||
__all__ = ("console",)
|
||||
|
||||
console = Console()
|
Loading…
Reference in a new issue