Profitroll
5adb004a2a
* `/report` command added * Updated to libbot 1.5 * Moved to [PhotosAPI_Client](https://git.end-play.xyz/profitroll/PhotosAPI_Client) v0.5.0 from using self-made API client * Video support (almost stable) * Bug fixes and improvements Co-authored-by: profitroll <vozhd.kk@gmail.com> Reviewed-on: #27
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
from datetime import datetime
|
|
|
|
from libbot import sync
|
|
|
|
from modules.database import col_banned, col_users
|
|
|
|
|
|
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 sync.config_get("admins", "bot"):
|
|
return False
|
|
|
|
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()
|
|
< sync.config_get("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()})
|