fix inactive users removal
This commit is contained in:
parent
28586ed19b
commit
cbf244ca45
14
main.py
14
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'<a href="tg://user?id={uid}">{user.name}</a> был удален '
|
||||
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'<a href="tg://user?id={uid}">{user.name}</a> был удален '
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user