media limit

This commit is contained in:
bakatrouble 2019-08-19 22:05:45 +03:00
parent 029d08d2aa
commit 8d564fb31b
2 changed files with 16 additions and 0 deletions

5
db.py
View File

@ -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

11
main.py
View File

@ -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: