feat(aurora): add the from_sql_all classmethod to the Moderation model
All checks were successful
Actions / Lint Code (Ruff & Pylint) (pull_request) Successful in 1m9s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 47s

This commit is contained in:
Seaswimmer 2024-06-02 23:53:19 -04:00
parent 73c9104882
commit 641f45d126
Signed by: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -119,8 +119,7 @@ class Moderation(AuroraGuildModel):
query = f"UPDATE moderation_{self.guild_id} SET timestamp = ?, moderation_type = ?, target_type = ?, moderator_id = ?, role_id = ?, duration = ?, end_timestamp = ?, reason = ?, resolved = ?, resolved_by = ?, resolve_reason = ?, expired = ?, changes = ?, metadata = ? WHERE moderation_id = ?;"
with connect() as database:
cursor = database.cursor()
cursor.execute(query, (
database.execute(query, (
self.timestamp.timestamp(),
self.moderation_type,
self.target_type,
@ -137,7 +136,6 @@ class Moderation(AuroraGuildModel):
dumps(self.metadata),
self.moderation_id,
))
cursor.close()
logger.debug("Row updated in moderation_%s!\n%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s",
self.moderation_id,
@ -219,6 +217,25 @@ class Moderation(AuroraGuildModel):
raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!")
@classmethod
def from_sql_all(cls, bot: Red, guild_id: int) -> List["Moderation"]:
from ..utilities.database import connect
query = f"SELECT * FROM moderation_{guild_id};"
with connect() as database:
cursor = database.cursor()
cursor.execute(query)
results = cursor.fetchall()
cursor.close()
if results:
cases = []
for result in results:
cases.append(cls.from_result(bot, result, guild_id))
return cases
return []
@classmethod
def log(
cls,