SeaCogs/aurora/models.py

63 lines
1.5 KiB
Python
Raw Normal View History

2024-05-04 13:41:11 -04:00
from typing import Dict, List, Optional
from discord import Guild
from pydantic import BaseModel
from 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}"
async def from_sql(self, moderation_id: int, guild: Guild):
""""""
database = connect()
cursor = database.cursor()
query = f"SELECT * FROM moderation_{guild.id} WHERE moderation_id = ?;"
cursor.execute(query, (moderation_id,))
result = cursor.fetchone()
cursor.close()
database.close()
if result:
(
self.moderation_id,
self.timestamp,
self.moderation_type,
self.target_type,
self.target_id,
self.moderator_id,
self.role_id,
self.duration,
self.end_timestamp,
self.reason,
self.resolved,
self.resolved_by,
self.resolve_reason,
self.expired,
self.changes,
self.metadata,
) = result[0:16]
return self