From a91311acd7a1d0bf4c24931e4428272154472239 Mon Sep 17 00:00:00 2001 From: EEKIM10 Date: Thu, 6 Oct 2022 09:45:42 +0100 Subject: [PATCH] views.py now actually handles errors --- utils/views.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/utils/views.py b/utils/views.py index de9a0e6..fb3de17 100644 --- a/utils/views.py +++ b/utils/views.py @@ -87,6 +87,7 @@ class VerifyView(discord.ui.View): max_length=7, ), title="Enter your student ID number", + timeout=120 ) async def callback(self, interaction: discord.Interaction): @@ -96,19 +97,24 @@ class VerifyView(discord.ui.View): return if not re.match(r"^B\d{6}$", st): - return await interaction.response.send_message( + btn.disabled = False + return await interaction.followup.send( "\N{cross mark} Invalid student ID.", delete_after=60 ) ex = await get_or_none(Student, id=st) if ex: - return await interaction.response.send_message( + btn.disabled = False + return await interaction.followup.send( "\N{cross mark} Student ID is already associated.", delete_after=60 ) - _code = await send_verification_code(interaction.user, st) + try: + _code = await send_verification_code(interaction.user, st) + 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) console.log(f"[green]Sent verification email to {interaction.user} ({interaction.user.id}/{st}): " @@ -127,9 +133,12 @@ class VerifyView(discord.ui.View): ephemeral=True, ) - await interaction1.response.send_modal(Modal()) + modal = Modal() + await interaction1.response.send_modal() btn.disabled = True await interaction1.edit_original_response(view=self) + await modal.wait() + await interaction1.edit_original_response(view=self) @discord.ui.button( label="Why do I need a verification code?",