dev #19

Merged
profitroll merged 98 commits from dev into master 2023-04-24 13:48:22 +03:00
2 changed files with 24 additions and 16 deletions
Showing only changes of commit bd9917fb17 - Show all commits

17
classes/user.py Normal file
View File

@ -0,0 +1,17 @@
from datetime import datetime
from modules.database import col_banned
class PosterUser():
def __init__(self, id: int):
self.id = id
def is_blocked(self) -> bool:
return False if col_banned.find_one({"user": self.id}) is None else True
def block(self) -> None:
if col_banned.find_one({"user": self.id}) is None:
col_banned.insert_one({"user": self.id, "date": datetime.now()})
def unblock(self) -> None:
col_banned.find_one_and_delete({"user": self.id})

View File

@ -1,27 +1,18 @@
from datetime import datetime, timezone from modules.app import app
from datetime import datetime
from modules.utils import configGet from modules.utils import configGet
from modules.database import col_users, col_banned from modules.database import col_users
from pyrogram.types.user_and_chats import User from pyrogram.types.user_and_chats import User
def subLimit(user: User) -> None: def subLimit(user: User) -> None:
if col_users.find_one_and_update({"user": user.id}, {"$set": {"cooldown": datetime.now(tz=timezone.utc)}}) is None: if col_users.find_one_and_update({"user": user.id}, {"$set": {"cooldown": datetime.now()}}) is None:
col_users.insert_one({"user": user.id, "cooldown": datetime.now(tz=timezone.utc)}) col_users.insert_one({"user": user.id, "cooldown": datetime.now()})
def subLimited(user: User) -> bool: def subLimited(user: User) -> bool:
if user.id == configGet("admin"): if user.id in app.admins:
return False return False
else: else:
db_record = col_users.find_one({"user": user.id}) db_record = col_users.find_one({"user": user.id})
if db_record is None: if db_record is None:
return False return False
return True if (datetime.now(tz=timezone.utc) - db_record["cooldown"].astimezone(timezone.utc)).total_seconds() < configGet("timeout", "submission") else False return True if (datetime.now() - 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})