From d2135cf65c8e9758f5ad588273d6b9e3872f8e6a Mon Sep 17 00:00:00 2001
From: Nihal Kumar <121309701+nihalxkumar@users.noreply.github.com>
Date: Mon, 28 Oct 2024 18:12:11 +0000
Subject: [PATCH] Update bot.py
---
bot/bot.py | 42 +++++++++++++++++++++---------------------
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/bot/bot.py b/bot/bot.py
index 78846b5..4ddc4d7 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -25,10 +25,10 @@
HEALTHCHECK_PORT = int(os.getenv("PORT", 8000))
# Constants
-VERIFICATION_CODE_LENGTH = 6
+OTP_LENGTH = 6
RATE_LIMIT_MAX_REQUESTS = 5
RATE_LIMIT_WINDOW = 600 # 10 minutes
-VERIFICATION_CODE_EXPIRY = 600 # 10 minutes
+OTP_EXPIRY = 600 # 10 minutes
EMAIL_DOMAIN = "@online.bits-pilani.ac.in"
BOT_EMAIL = "noreply@bits-bot.sattwyk.com"
@@ -68,7 +68,7 @@ def __init__(self):
super().__init__(title="BITS Pilani Email Verification")
self.email = TextInput(
label="Enter your BITS Pilani student email",
- placeholder=f"2023XXXXX{EMAIL_DOMAIN}",
+ placeholder=f"202XXXXXX{EMAIL_DOMAIN}",
required=True,
)
self.add_item(self.email)
@@ -93,29 +93,29 @@ async def on_submit(self, interaction: discord.Interaction):
raise ValueError("Enter a valid BITS Pilani student email.")
verification_code = "".join(
- random.choices("0123456789", k=VERIFICATION_CODE_LENGTH)
+ random.choices("0123456789", k=OTP_LENGTH)
)
email_params = {
"from": f"BITS Discord Bot <{BOT_EMAIL}>",
"to": [email_input.email],
- "subject": "Discord Verification Code",
- "html": f"Your verification code is: {verification_code}",
+ "subject": "Discord Email Verification OTP",
+ "html": f"Your OTP is: {verification_code}",
}
if not resend.Emails.send(email_params):
raise ValueError(
- "Failed to send verification email. Please try again later."
+ "Failed to send the OTP. Please try again later."
)
await redis_client.set(
f"verify:{interaction.user.id}",
f"{verification_code}:{email_input.email}",
- ex=VERIFICATION_CODE_EXPIRY,
+ ex=OTP_EXPIRY,
)
await interaction.followup.send(
- f"A verification code has been sent to **{email_input.email}**. Please use `/verify` again to enter the code or click the button below.\nNOTE: The code will expire in **10 minutes**.",
+ f"An OTP has been sent to **{email_input.email}**. \nNOTE: The code will expire in **10 minutes**. \nIf Enter Code Button doesn't appear use `/verify` again",
ephemeral=True,
)
@@ -140,11 +140,11 @@ class CodeModal(Modal):
def __init__(self):
super().__init__(title="Code Verification")
self.code = TextInput(
- label="Enter the verification code",
- placeholder="123456",
+ label="Enter the OTP",
+ placeholder="xxxxxx",
required=True,
- min_length=VERIFICATION_CODE_LENGTH,
- max_length=VERIFICATION_CODE_LENGTH,
+ min_length=OTP_LENGTH,
+ max_length=OTP_LENGTH,
)
self.add_item(self.code)
@@ -161,15 +161,15 @@ async def on_submit(self, interaction: discord.Interaction):
stored_data = await redis_client.get(f"verify:{interaction.user.id}")
if not stored_data:
- raise ValueError("Verification code expired or not found")
+ raise ValueError("OTP expired or not found")
correct_code, _ = stored_data.split(":")
if self.code.value != correct_code:
- raise ValueError("Incorrect verification code")
+ raise ValueError("Incorrect OTP")
verified_role = discord.utils.get(interaction.guild.roles, name="Verified")
if not verified_role:
- raise ValueError("Verified role not found")
+ raise ValueError("@Verified role not found")
await interaction.user.add_roles(verified_role)
await redis_client.delete(f"verify:{interaction.user.id}")
@@ -181,7 +181,7 @@ async def on_submit(self, interaction: discord.Interaction):
except ValueError as e:
await interaction.followup.send(str(e), ephemeral=True)
- logger.error(f"Code verification error: {str(e)}")
+ logger.error(f"OTP verification error: {str(e)}")
except Exception as e:
await interaction.followup.send(
"An unexpected error occurred. Please try again later.", ephemeral=True
@@ -218,8 +218,8 @@ def __init__(self, email=True, code=True):
if code:
self.add_item(
Button(
- label="Enter Code",
- custom_id="code_button",
+ label="Enter OTP",
+ custom_id="otp_button",
style=discord.ButtonStyle.secondary
if email
else discord.ButtonStyle.primary,
@@ -239,7 +239,7 @@ async def verify(interaction: discord.Interaction):
view = VerifyView()
await interaction.followup.send(
- "Hi! To access the unlocked channels, you need to get verified.\nChoose an option below to start the verification process:",
+ "Hey There!\nChoose an option below to start the verification process:",
view=view,
ephemeral=True,
)
@@ -258,7 +258,7 @@ async def on_interaction(interaction: discord.Interaction):
if interaction.type == discord.InteractionType.component:
if interaction.data["custom_id"] == "email_button":
await interaction.response.send_modal(EmailModal())
- elif interaction.data["custom_id"] == "code_button":
+ elif interaction.data["custom_id"] == "otp_button":
await interaction.response.send_modal(CodeModal())