WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
Showing only changes of commit 641f45d126 - Show all commits

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 = ?;" 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: with connect() as database:
cursor = database.cursor() database.execute(query, (
cursor.execute(query, (
self.timestamp.timestamp(), self.timestamp.timestamp(),
self.moderation_type, self.moderation_type,
self.target_type, self.target_type,
@ -137,7 +136,6 @@ class Moderation(AuroraGuildModel):
dumps(self.metadata), dumps(self.metadata),
self.moderation_id, 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", 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, self.moderation_id,
@ -219,6 +217,25 @@ class Moderation(AuroraGuildModel):
raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!") 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 @classmethod
def log( def log(
cls, cls,