from modules.app import app from datetime import datetime from modules.database import col_banned, col_users from modules.utils import configGet class PosterUser: def __init__(self, id: int): self.id = id def is_blocked(self) -> bool: """Check if user is banned from submitting content. ### Returns: `bool`: Must be `True` if banned and `False` if not """ return False if col_banned.find_one({"user": self.id}) is None else True def block(self) -> None: """Ban user from using command and submitting content.""" if col_banned.find_one({"user": self.id}) is None: col_banned.insert_one({"user": self.id, "date": datetime.now()}) def unblock(self) -> None: """Allow user to use command and submit posts again.""" col_banned.find_one_and_delete({"user": self.id}) def is_limited(self) -> bool: """Check if user is on a cooldown after submitting something. ### Returns: `bool`: Must be `True` if on the cooldown and `False` if not """ if self.id in app.admins: return False else: db_record = col_users.find_one({"user": self.id}) if db_record is None: return False return ( True if (datetime.now() - db_record["cooldown"]).total_seconds() < configGet("timeout", "submission") else False ) def limit(self) -> None: """Restart user's cooldown. Used after post has been submitted.""" if ( col_users.find_one_and_update( {"user": self.id}, {"$set": {"cooldown": datetime.now()}} ) is None ): col_users.insert_one({"user": self.id, "cooldown": datetime.now()})