dev #19
17
classes/user.py
Normal file
17
classes/user.py
Normal 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})
|
@ -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.database import col_users, col_banned
|
||||
from modules.database import col_users
|
||||
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)})
|
||||
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()})
|
||||
|
||||
def subLimited(user: User) -> bool:
|
||||
if user.id == configGet("admin"):
|
||||
if user.id in app.admins:
|
||||
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"].astimezone(timezone.utc)).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})
|
||||
return True if (datetime.now() - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False
|
Reference in New Issue
Block a user