Skip to content

Commit

Permalink
add verify slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
e-zhang09 committed Apr 2, 2024
1 parent 518bce2 commit d97c016
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions apps/discordbot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# TEST_SERVER_CHANNEL_ID = 805590450136154125 # CSUA-Test
CSUA_PB_ROLE_ID = 784907966532288542
CSUA_PROSP_ROLE_ID = config("CSUA_PROSP_ROLE_ID", default=805635820353617920, cast=int)
CSUA_VERIFIED_ROLE_ID = 785418569412116513

TIMEOUT_SECS = 10

Expand Down Expand Up @@ -101,6 +102,9 @@ async def on_ready(self):
self.prosps_role: typing.Optional[Role] = get(
self.csua_guild.roles, id=CSUA_PROSP_ROLE_ID
)
self.verified_role: typing.Optional[Role] = get(
self.csua_guild.roles, id=CSUA_VERIFIED_ROLE_ID
)

async def on_message(self, message):
author = message.author
Expand Down Expand Up @@ -226,6 +230,49 @@ async def on_message(self, message):
await channel.send(f"!dm: {e} generic_exception")

def add_commands(self):
@self.slash_command_tree.command(
name="verify",
description="Welcome to the CSUA! You may use this command to get verified.",
guild=discord.Object(id=CSUA_GUILD_ID),
)
@app_commands.describe(
email_address="Your @berkeley.edu email address. New admits are still welcome to chat in unverified channels!"
)
async def oh_check_in(interaction, email_address: str):
try:
if self.verified_role not in interaction.user.roles:
try:
author = interaction.user
validate_email(email_address)
if email_address.endswith("berkeley.edu"):
send_verify_mail(
email_address, author.name + "#" + author.discriminator
)
await interaction.response.send_message(
f"A verification email has been sent to {email_address}",
ephemeral=True,
)
await self.test_channel.send(
f"{author.name}(id: {author.id}) was sent verification email"
)
else:
await interaction.response.send_message(
f"{email_address} is not a berkeley email.",
ephemeral=True,
)
except ValidationError as e:
await interaction.response.send_message(
f"{email_address} is not a valid email. Details: {e}",
ephemeral=True,
)
else:
await interaction.response.send_message(
"You are verified already!",
ephemeral=True,
)
except Exception as e:
print(e)

@self.slash_command_tree.command(
name="oh-cover",
description="Hi officers! Please use this command to cover someone else's office hour.",
Expand Down

0 comments on commit d97c016

Please sign in to comment.