Skip to content

Commit b6cdd47

Browse files
committed
fix: handle slow or expired interactions better
1 parent 41a0538 commit b6cdd47

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

bot/main.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,21 @@ async def verify_user(ctx: commands.Context):
279279
await ctx.reply("This command has been removed, please use /verify instead.")
280280
return
281281

282+
if ctx.interaction.is_expired():
283+
await ctx.reply(
284+
"Your command expired due to some unknown error, please try again."
285+
)
286+
return
287+
288+
# defer because sometimes the command can take too long if the database connection
289+
# is slow.
290+
# it is important that is is ephemeral. It has a secret link that only the
291+
# invoker must see.
292+
await ctx.defer(ephemeral=True)
282293
author = ctx.message.author
283294
if await is_verified(author.id):
284295
# user has already previously verified
296+
await ctx.interaction.followup.send(f"You are CAS-verified!", ephemeral=True)
285297
await post_verification(ctx, author)
286298
return
287299

@@ -298,9 +310,8 @@ async def verify_user(ctx: commands.Context):
298310
expire_time = time.time() + VERIFY_TIMEOUT_SECONDS
299311
token_to_id[token] = (author.id, expire_time)
300312

301-
# it is important that is is ephemeral. It has a secret link that only the
302-
# invoker must see.
303-
await ctx.send(
313+
# use followup and not ctx reply/send because this message HAS to be ephemeral
314+
await ctx.interaction.followup.send(
304315
f"[This](<{BASE_URL}/cas?token={token}>) is your verification link, click "
305316
"it to login and verify yourself.\n"
306317
"IMPORTANT NOTE: Above link is secret, do not share with anyone! "

0 commit comments

Comments
 (0)