This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramPoster/modules/submissions.py

27 lines
1.2 KiB
Python
Raw Normal View History

2023-02-15 15:06:06 +02:00
from datetime import datetime, timezone
from modules.utils import configGet
from modules.database import col_users, col_banned
from pyrogram.types.user_and_chats import User
2023-01-10 13:52:44 +02:00
2023-02-15 15:06:06 +02:00
def subLimit(user: User) -> None:
if col_users.find_one_and_update({"user": user.id}, {"$set": {"cooldown": datetime.now(tz=timezone.utc)}}) is None:
col_users.insert_one({"user": user.id, "cooldown": datetime.now(tz=timezone.utc)})
2023-01-10 13:52:44 +02:00
2023-02-15 15:06:06 +02:00
def subLimited(user: User) -> bool:
2023-01-10 13:52:44 +02:00
if user.id == configGet("admin"):
return False
else:
2023-02-15 15:06:06 +02:00
db_record = col_users.find_one({"user": user.id})
if db_record is None:
2023-01-10 13:52:44 +02:00
return False
2023-02-16 17:41:01 +02:00
return True if (datetime.now(tz=timezone.utc) - db_record["cooldown"].astimezone(timezone.utc)).total_seconds() < configGet("timeout", "submission") else False
2023-01-10 13:52:44 +02:00
2023-02-15 15:06:06 +02:00
def subBlocked(user: User) -> bool:
return False if col_banned.find_one({"user": user.id}) is None else True
2023-01-10 13:52:44 +02:00
2023-02-15 15:06:06 +02:00
def subBlock(user: User) -> None:
if col_banned.find_one({"user": user.id}) is None:
col_banned.insert_one({"user": user.id, "date": datetime.now(tz=timezone.utc)})
def subUnblock(user: User) -> None:
col_banned.find_one_and_delete({"user": user.id})