media limit
This commit is contained in:
parent
029d08d2aa
commit
8d564fb31b
5
db.py
5
db.py
@ -1,3 +1,5 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from BTrees.IIBTree import IIBTree
|
from BTrees.IIBTree import IIBTree
|
||||||
from ZODB import DB
|
from ZODB import DB
|
||||||
from ZODB.Connection import Connection
|
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):
|
if not hasattr(user, 'messages_forward') or not isinstance(user.messages_forward, IIBTree):
|
||||||
user.messages_forward = IIBTree()
|
user.messages_forward = IIBTree()
|
||||||
user.messages_reverse = IIBTree()
|
user.messages_reverse = IIBTree()
|
||||||
|
# migration 2
|
||||||
|
if not hasattr(conn.root, 'last_media'):
|
||||||
|
conn.root.last_media = datetime.now()
|
||||||
# end migrations
|
# end migrations
|
||||||
commit()
|
commit()
|
||||||
return conn
|
return conn
|
||||||
|
11
main.py
11
main.py
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
from datetime import datetime, timedelta
|
||||||
from html import escape
|
from html import escape
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
from time import sleep
|
from time import sleep
|
||||||
@ -232,6 +233,16 @@ def users_list(bot: Bot, update: Update):
|
|||||||
|
|
||||||
|
|
||||||
def _process_message(bot: Bot, m: Message):
|
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
|
current_chat = m.chat_id
|
||||||
users = conn.root.subscribers # type: Dict[int, Subscriber]
|
users = conn.root.subscribers # type: Dict[int, Subscriber]
|
||||||
if current_chat not in users:
|
if current_chat not in users:
|
||||||
|
Loading…
Reference in New Issue
Block a user