mirror of
https://github.com/wlinator/luminara.git
synced 2024-10-02 18:03:12 +00:00
refactor: Add ModLogService for managing moderation log channels
This commit is contained in:
parent
42160683e3
commit
e4048e0648
1 changed files with 31 additions and 0 deletions
31
services/moderation/modlog_service.py
Normal file
31
services/moderation/modlog_service.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
from db.database import execute_query, select_query_one
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ModLogService:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def set_modlog_channel(self, guild_id: int, channel_id: int) -> None:
|
||||
query: str = """
|
||||
INSERT INTO mod_log (guild_id, channel_id, is_enabled)
|
||||
VALUES (%s, %s, TRUE)
|
||||
ON DUPLICATE KEY UPDATE channel_id = VALUES(channel_id), is_enabled = TRUE, updated_at = CURRENT_TIMESTAMP
|
||||
"""
|
||||
execute_query(query, (guild_id, channel_id))
|
||||
|
||||
def disable_modlog_channel(self, guild_id: int) -> None:
|
||||
query: str = """
|
||||
UPDATE mod_log
|
||||
SET is_enabled = FALSE, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE guild_id = %s
|
||||
"""
|
||||
execute_query(query, (guild_id,))
|
||||
|
||||
def fetch_modlog_channel_id(self, guild_id: int) -> Optional[dict]:
|
||||
query: str = """
|
||||
SELECT * FROM mod_log
|
||||
WHERE guild_id = %s AND is_enabled = TRUE
|
||||
"""
|
||||
result = select_query_one(query, (guild_id,))
|
||||
return dict(result) if result else None
|
Loading…
Reference in a new issue