From 82962614bee0a8130e6f71ec95bba9619f4d91d6 Mon Sep 17 00:00:00 2001 From: KimmyXYC Date: Tue, 6 Feb 2024 09:49:48 +0800 Subject: [PATCH] fix: Check up status before del from the dict --- App/Controller.py | 10 +++++++--- App/JoinRequest.py | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/App/Controller.py b/App/Controller.py index ffac14c..8f6fd94 100644 --- a/App/Controller.py +++ b/App/Controller.py @@ -72,7 +72,9 @@ async def delete_pinned_message(message: types.Message): async def handle_new_chat_members(request: types.ChatJoinRequest): join_request_id = cal_md5(f"{request.chat.id}@{request.from_user.id}") if join_request_id in self.join_tasks: - return + join_task = self.join_tasks[join_request_id] + if not join_task.ccheck_up_status(): + return join_task = JoinRequest(request.chat.id, request.from_user.id, self.bot_id, self.config) self.join_tasks[join_request_id] = join_task await join_task.handle_join_request(bot, request, self.db) @@ -86,8 +88,10 @@ async def handle_callback_query(callback_query: types.CallbackQuery): action = callback_query.data.split()[0] join_request_id = callback_query.data.split()[1] join_tasks = self.join_tasks.get(join_request_id, None) - if join_tasks: - await join_tasks.handle_button(bot, callback_query, action) + if join_tasks is None: + return + await join_tasks.handle_button(bot, callback_query, action) + if join_tasks.ccheck_up_status(): try: del self.join_tasks[join_request_id] except KeyError: diff --git a/App/JoinRequest.py b/App/JoinRequest.py index 5a9a7b8..827918c 100644 --- a/App/JoinRequest.py +++ b/App/JoinRequest.py @@ -25,6 +25,9 @@ def __init__(self, chat_id, user_id, bot_id, config): self.notice_message = None self.polling = None + def check_up_status(self): + return self.finished + async def handle_join_request(self, bot, request: types.ChatJoinRequest, db): self.request = request self.bot_member = await bot.get_chat_member(self.chat_id, self.bot_id) @@ -160,6 +163,7 @@ async def handle_join_request(self, bot, request: types.ChatJoinRequest, db): await request.decline() except Exception as e: logger.error(f"Process request User_id:{self.user_id} in Chat_id:{self.chat_id}: {e}") + self.finished = True await asyncio.sleep(60)