mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Now make verified people supply names
This commit is contained in:
parent
e10cac324e
commit
d36791e304
3 changed files with 29 additions and 6 deletions
|
@ -27,8 +27,8 @@ class VerifyCog(commands.Cog):
|
|||
if channel:
|
||||
try:
|
||||
await ctx.author.send(
|
||||
f"You have been automatically de-verified. Please re-verify by going to {channel.mention} and"
|
||||
f" typing </verify:{ctx.command.id}>."
|
||||
f"You have been automatically de-verified. Please re-verify by going to {channel.mention} "
|
||||
f"and typing </verify:{ctx.command.id}>."
|
||||
)
|
||||
except discord.Forbidden:
|
||||
pass
|
||||
|
|
|
@ -46,12 +46,14 @@ class VerifyCode(orm.Model):
|
|||
"code": orm.String(min_length=8, max_length=64, unique=True),
|
||||
"bind": orm.BigInteger(),
|
||||
"student_id": orm.String(min_length=7, max_length=7),
|
||||
"name": orm.String(min_length=2, max_length=32),
|
||||
}
|
||||
if TYPE_CHECKING:
|
||||
id: int
|
||||
code: str
|
||||
bind: int
|
||||
student_id: str
|
||||
name: str
|
||||
|
||||
|
||||
class Student(orm.Model):
|
||||
|
@ -61,11 +63,13 @@ class Student(orm.Model):
|
|||
"entry_id": orm.UUID(primary_key=True, default=uuid.uuid4),
|
||||
"id": orm.String(min_length=7, max_length=7, unique=True),
|
||||
"user_id": orm.BigInteger(unique=True),
|
||||
"name": orm.String(min_length=2, max_length=32),
|
||||
}
|
||||
if TYPE_CHECKING:
|
||||
entry_id: uuid.UUID
|
||||
id: str
|
||||
user_id: int
|
||||
name: str
|
||||
|
||||
|
||||
class BannedStudentID(orm.Model):
|
||||
|
|
|
@ -51,16 +51,27 @@ class VerifyView(View):
|
|||
ban = await get_or_none(BannedStudentID, student_id=existing.student_id)
|
||||
if ban is not None:
|
||||
self.stop()
|
||||
return await interaction.user.ban(
|
||||
return await interaction.user.kick(
|
||||
reason=f"Attempted to verify with banned student ID {ban.student_id}"
|
||||
f" (originally associated with account {ban.associated_account})"
|
||||
)
|
||||
await Student.objects.create(id=existing.student_id, user_id=interaction.user.id)
|
||||
await Student.objects.create(
|
||||
id=existing.student_id,
|
||||
user_id=interaction.user.id,
|
||||
name=existing.name
|
||||
)
|
||||
await existing.delete()
|
||||
role = discord.utils.find(lambda r: r.name.lower() == "verified", interaction.guild.roles)
|
||||
member = await interaction.guild.fetch_member(interaction.user.id)
|
||||
if role and role < interaction.guild.me.top_role:
|
||||
member = await interaction.guild.fetch_member(interaction.user.id)
|
||||
await member.add_roles(role, reason="Verified")
|
||||
try:
|
||||
await member.edit(
|
||||
nick=f"{existing.name}",
|
||||
reason="Verified"
|
||||
)
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
console.log(f"[green]{interaction.user} verified ({interaction.user.id}/{existing.student_id})")
|
||||
self.stop()
|
||||
return await interaction.followup.send(
|
||||
|
@ -84,6 +95,13 @@ class VerifyView(View):
|
|||
min_length=7,
|
||||
max_length=7,
|
||||
),
|
||||
discord.ui.InputText(
|
||||
custom_id="name",
|
||||
label="What is your name?",
|
||||
placeholder="Nicknames are okay too.",
|
||||
min_length=2,
|
||||
max_length=32,
|
||||
),
|
||||
title="Enter your student ID number",
|
||||
timeout=120,
|
||||
)
|
||||
|
@ -110,7 +128,8 @@ class VerifyView(View):
|
|||
except Exception as e:
|
||||
return await interaction.followup.send(f"\N{cross mark} Failed to send email - {e}. Try again?")
|
||||
console.log(f"Sending verification email to {interaction.user} ({interaction.user.id}/{st})...")
|
||||
__code = await VerifyCode.objects.create(code=_code, bind=interaction.id, student_id=st)
|
||||
name = self.children[1].value
|
||||
__code = await VerifyCode.objects.create(code=_code, bind=interaction.id, student_id=st, name=name)
|
||||
console.log(
|
||||
f"[green]Sent verification email to {interaction.user} ({interaction.user.id}/{st}): " f"{_code!r}"
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue