From f3cf4fcb5a24ba1f85646e38d001a893ef28d84d Mon Sep 17 00:00:00 2001 From: Conatum Date: Wed, 22 Dec 2021 08:57:57 +0200 Subject: [PATCH] fix (accountability): Disallow near bookings. Don't allow members to book within 11 minutes of the room start. Patches a race condition where the open room doesn't include the member. --- bot/modules/accountability/commands.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bot/modules/accountability/commands.py b/bot/modules/accountability/commands.py index 6180d4bd..a0d19509 100644 --- a/bot/modules/accountability/commands.py +++ b/bot/modules/accountability/commands.py @@ -39,6 +39,7 @@ def time_format(time): time.timestamp() + 3600, ) + user_locks = {} # Map userid -> ctx @@ -229,7 +230,10 @@ async def cmd_rooms(ctx): start_time + datetime.timedelta(hours=n) for n in range(1, 25) ) - times = [time for time in times if time not in already_joined_times] + times = [ + time for time in times + if time not in already_joined_times and (time - utc_now()).total_seconds() > 660 + ] lines = [ "`[{num:>2}]` | `{count:>{count_pad}}` attending | {time}".format( num=i, @@ -255,7 +259,7 @@ async def cmd_rooms(ctx): await ctx.cancellable( out_msg, cancel_message="Booking menu cancelled, no sessions were booked.", - timeout=70 + timeout=60 ) def check(msg): @@ -265,7 +269,7 @@ async def cmd_rooms(ctx): with ensure_exclusive(ctx): try: - message = await ctx.client.wait_for('message', check=check, timeout=60) + message = await ctx.client.wait_for('message', check=check, timeout=30) except asyncio.TimeoutError: try: await out_msg.edit( @@ -325,6 +329,7 @@ async def cmd_rooms(ctx): ) # Handle case where the slot has already opened + # TODO: Fix this, doesn't always work aguild = AGuild.cache.get(ctx.guild.id, None) if aguild: if aguild.upcoming_slot and aguild.upcoming_slot.start_time in to_book: