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 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)}) def subLimited(user: User) -> bool: if user.id == configGet("admin"): return False else: db_record = col_users.find_one({"user": user.id}) if db_record is None: return False return True if (datetime.now(tz=timezone.utc) - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False def subBlocked(user: User) -> bool: return False if col_banned.find_one({"user": user.id}) is None else True 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})