mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-20 02:26:32 +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:
|
if channel:
|
||||||
try:
|
try:
|
||||||
await ctx.author.send(
|
await ctx.author.send(
|
||||||
f"You have been automatically de-verified. Please re-verify by going to {channel.mention} and"
|
f"You have been automatically de-verified. Please re-verify by going to {channel.mention} "
|
||||||
f" typing </verify:{ctx.command.id}>."
|
f"and typing </verify:{ctx.command.id}>."
|
||||||
)
|
)
|
||||||
except discord.Forbidden:
|
except discord.Forbidden:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -46,12 +46,14 @@ class VerifyCode(orm.Model):
|
||||||
"code": orm.String(min_length=8, max_length=64, unique=True),
|
"code": orm.String(min_length=8, max_length=64, unique=True),
|
||||||
"bind": orm.BigInteger(),
|
"bind": orm.BigInteger(),
|
||||||
"student_id": orm.String(min_length=7, max_length=7),
|
"student_id": orm.String(min_length=7, max_length=7),
|
||||||
|
"name": orm.String(min_length=2, max_length=32),
|
||||||
}
|
}
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
id: int
|
id: int
|
||||||
code: str
|
code: str
|
||||||
bind: int
|
bind: int
|
||||||
student_id: str
|
student_id: str
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
class Student(orm.Model):
|
class Student(orm.Model):
|
||||||
|
@ -61,11 +63,13 @@ class Student(orm.Model):
|
||||||
"entry_id": orm.UUID(primary_key=True, default=uuid.uuid4),
|
"entry_id": orm.UUID(primary_key=True, default=uuid.uuid4),
|
||||||
"id": orm.String(min_length=7, max_length=7, unique=True),
|
"id": orm.String(min_length=7, max_length=7, unique=True),
|
||||||
"user_id": orm.BigInteger(unique=True),
|
"user_id": orm.BigInteger(unique=True),
|
||||||
|
"name": orm.String(min_length=2, max_length=32),
|
||||||
}
|
}
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
entry_id: uuid.UUID
|
entry_id: uuid.UUID
|
||||||
id: str
|
id: str
|
||||||
user_id: int
|
user_id: int
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
class BannedStudentID(orm.Model):
|
class BannedStudentID(orm.Model):
|
||||||
|
|
|
@ -51,16 +51,27 @@ class VerifyView(View):
|
||||||
ban = await get_or_none(BannedStudentID, student_id=existing.student_id)
|
ban = await get_or_none(BannedStudentID, student_id=existing.student_id)
|
||||||
if ban is not None:
|
if ban is not None:
|
||||||
self.stop()
|
self.stop()
|
||||||
return await interaction.user.ban(
|
return await interaction.user.kick(
|
||||||
reason=f"Attempted to verify with banned student ID {ban.student_id}"
|
reason=f"Attempted to verify with banned student ID {ban.student_id}"
|
||||||
f" (originally associated with account {ban.associated_account})"
|
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()
|
await existing.delete()
|
||||||
role = discord.utils.find(lambda r: r.name.lower() == "verified", interaction.guild.roles)
|
role = discord.utils.find(lambda r: r.name.lower() == "verified", interaction.guild.roles)
|
||||||
if role and role < interaction.guild.me.top_role:
|
|
||||||
member = await interaction.guild.fetch_member(interaction.user.id)
|
member = await interaction.guild.fetch_member(interaction.user.id)
|
||||||
|
if role and role < interaction.guild.me.top_role:
|
||||||
await member.add_roles(role, reason="Verified")
|
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})")
|
console.log(f"[green]{interaction.user} verified ({interaction.user.id}/{existing.student_id})")
|
||||||
self.stop()
|
self.stop()
|
||||||
return await interaction.followup.send(
|
return await interaction.followup.send(
|
||||||
|
@ -84,6 +95,13 @@ class VerifyView(View):
|
||||||
min_length=7,
|
min_length=7,
|
||||||
max_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",
|
title="Enter your student ID number",
|
||||||
timeout=120,
|
timeout=120,
|
||||||
)
|
)
|
||||||
|
@ -110,7 +128,8 @@ class VerifyView(View):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return await interaction.followup.send(f"\N{cross mark} Failed to send email - {e}. Try again?")
|
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})...")
|
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(
|
console.log(
|
||||||
f"[green]Sent verification email to {interaction.user} ({interaction.user.id}/{st}): " f"{_code!r}"
|
f"[green]Sent verification email to {interaction.user} ({interaction.user.id}/{st}): " f"{_code!r}"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue