43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
from typing import Dict, List, Optional
|
|
|
|
from discord import Guild
|
|
from pydantic import BaseModel
|
|
|
|
from aurora.utilities.database import connect
|
|
|
|
|
|
class Moderation(BaseModel):
|
|
moderation_id: int
|
|
timestamp: int
|
|
moderation_type: str
|
|
target_type: str
|
|
target_id: int
|
|
moderator_id: int
|
|
resolved: bool
|
|
expired: bool
|
|
duration: str
|
|
end_timestamp: int
|
|
reason: str
|
|
changes: List[Dict]
|
|
metadata: Dict
|
|
resolved_by: Optional[int] = None
|
|
resolve_reason: Optional[str] = None
|
|
role_id: Optional[int] = None
|
|
|
|
def __str__(self):
|
|
return f"{self.moderation_type} {self.target_type} {self.target_id} {self.reason}"
|
|
|
|
@classmethod
|
|
def from_sql(cls, moderation_id: int, guild: Guild):
|
|
query = f"SELECT * FROM moderation_{guild.id} WHERE moderation_id = ?;"
|
|
|
|
with connect() as database, database.cursor() as cursor:
|
|
cursor.execute(query, (moderation_id,))
|
|
result = cursor.fetchone()
|
|
|
|
if result:
|
|
moderation_data = dict(zip(cls.model_fields, result))
|
|
moderation = cls(**moderation_data)
|
|
return moderation
|
|
|
|
return None
|