WIP: Moderation type registry #26
1 changed files with 10 additions and 29 deletions
|
@ -27,36 +27,17 @@ class Moderation(BaseModel):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.moderation_type} {self.target_type} {self.target_id} {self.reason}"
|
return f"{self.moderation_type} {self.target_type} {self.target_id} {self.reason}"
|
||||||
|
|
||||||
async def from_sql(self, moderation_id: int, guild: Guild):
|
@classmethod
|
||||||
""""""
|
def from_sql(cls, moderation_id: int, guild: Guild):
|
||||||
database = connect()
|
|
||||||
cursor = database.cursor()
|
|
||||||
|
|
||||||
query = f"SELECT * FROM moderation_{guild.id} WHERE moderation_id = ?;"
|
query = f"SELECT * FROM moderation_{guild.id} WHERE moderation_id = ?;"
|
||||||
|
|
||||||
|
with connect() as database, database.cursor() as cursor:
|
||||||
cursor.execute(query, (moderation_id,))
|
cursor.execute(query, (moderation_id,))
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
database.close()
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
(
|
moderation_data = dict(zip(cls.model_fields, result))
|
||||||
self.moderation_id,
|
moderation = cls(**moderation_data)
|
||||||
self.timestamp,
|
return moderation
|
||||||
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
|
return None
|
||||||
|
|
Loading…
Reference in a new issue