Skip to content

Commit

Permalink
fix: Check up status before del from the dict
Browse files Browse the repository at this point in the history
  • Loading branch information
KimmyXYC committed Feb 6, 2024
1 parent 29fd25a commit 8296261
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 7 additions & 3 deletions App/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions App/JoinRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 8296261

Please sign in to comment.