From cbf244ca45898d8f9af6dd82422a9714cc0a816d Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Sun, 17 Mar 2019 15:07:38 +0300 Subject: [PATCH] fix inactive users removal --- main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 772b12d..e100f2b 100755 --- a/main.py +++ b/main.py @@ -184,6 +184,8 @@ def _process_media_group(bot: Bot, messages: List[Message]): elif hasattr(message, 'audio') and message.audio: media_group.append(InputMediaAudio(message.audio.file_id, caption=caption, parse_mode='html')) + remove_uids = [] + for uid, user in users.items(): sleep(.02) @@ -199,8 +201,7 @@ def _process_media_group(bot: Bot, messages: List[Message]): user.messages_forward[r.message_id] = conn.root.counter user.messages_reverse[conn.root.counter] = r.message_id except Unauthorized: - user = _remove_user(uid) - commit() + remove_uids.append(uid) bot.send_message(MANAGEMENT_CHAT, f'{user.name} был удален ' f'из-за блокировки бота', parse_mode='html') except Exception: @@ -208,6 +209,8 @@ def _process_media_group(bot: Bot, messages: List[Message]): sentry_sdk.capture_exception() conn.root.counter += len(messages) commit() + for uid in remove_uids: + _remove_user(uid) def _process_message(bot: Bot, m: Message): @@ -228,6 +231,8 @@ def _process_message(bot: Bot, m: Message): if m.reply_to_message and m.reply_to_message.message_id in users[current_chat].messages_forward: reply_to_message_internal_id = users[current_chat].messages_forward[m.reply_to_message.message_id] + remove_uids = [] + for uid, user in users.items(): sleep(.02) @@ -285,8 +290,7 @@ def _process_message(bot: Bot, m: Message): user.messages_forward[r.message_id] = conn.root.counter user.messages_reverse[conn.root.counter] = r.message_id except Unauthorized: - user = _remove_user(uid) - commit() + remove_uids.append(uid) bot.send_message(MANAGEMENT_CHAT, f'{user.name} был удален ' f'из-за блокировки бота', parse_mode='html') except Exception: @@ -294,6 +298,8 @@ def _process_message(bot: Bot, m: Message): sentry_sdk.capture_exception() conn.root.counter += 1 commit() + for uid in remove_uids: + _remove_user(uid) def task_queue(u: Updater):