diff --git a/db.py b/db.py index f4420a7..a3bfa2f 100644 --- a/db.py +++ b/db.py @@ -1,3 +1,5 @@ +from datetime import datetime + from BTrees.IIBTree import IIBTree from ZODB import DB from ZODB.Connection import Connection @@ -21,6 +23,9 @@ def get_conn(read_only=False) -> Connection: if not hasattr(user, 'messages_forward') or not isinstance(user.messages_forward, IIBTree): user.messages_forward = IIBTree() user.messages_reverse = IIBTree() + # migration 2 + if not hasattr(conn.root, 'last_media'): + conn.root.last_media = datetime.now() # end migrations commit() return conn diff --git a/main.py b/main.py index 52e7f87..8bfccd9 100755 --- a/main.py +++ b/main.py @@ -2,6 +2,7 @@ import logging import traceback +from datetime import datetime, timedelta from html import escape from queue import Queue, Empty from time import sleep @@ -232,6 +233,16 @@ def users_list(bot: Bot, update: Update): def _process_message(bot: Bot, m: Message): + if m.sticker or m.animation: + delta = datetime.now() - conn.root.last_media + if delta < timedelta(seconds=15): + bot.send_message( + m.from_user.id, + 'Не вайпи, до следующей гифки/стикера осталось {} секунд'.format(15 - int(delta.total_seconds())) + ) + return + conn.root.last_media = datetime.now() + commit() current_chat = m.chat_id users = conn.root.subscribers # type: Dict[int, Subscriber] if current_chat not in users: