1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 18:23:12 +00:00
Lumi/services/blacklist_service.py
2024-08-29 09:38:08 -04:00

39 lines
1.2 KiB
Python

from db import database
class BlacklistUserService:
def __init__(self, user_id: int) -> None:
self.user_id: int = user_id
def add_to_blacklist(self, reason: str | None = None) -> None:
"""
Adds a user to the blacklist with the given reason.
Args:
reason (str): The reason for blacklisting the user.
"""
query: str = """
INSERT INTO blacklist_user (user_id, reason)
VALUES (%s, %s)
ON DUPLICATE KEY UPDATE reason = VALUES(reason)
"""
database.execute_query(query, (self.user_id, reason))
@staticmethod
def is_user_blacklisted(user_id: int) -> bool:
"""
Checks if a user is currently blacklisted.
Args:
user_id (int): The ID of the user to check.
Returns:
bool: True if the user is blacklisted, False otherwise.
"""
query: str = """
SELECT active
FROM blacklist_user
WHERE user_id = %s
"""
result: list[tuple[bool]] = database.select_query(query, (user_id,))
return any(active for (active,) in result)