WIP: Moderation type registry #26

Closed
cswimr wants to merge 146 commits from aurora-3rd-party into main
Showing only changes of commit 99d95afe07 - Show all commits

View file

@ -202,7 +202,7 @@ class Moderation(AuroraGuildModel):
return cls.from_dict(bot=bot, data=case) return cls.from_dict(bot=bot, data=case)
@classmethod @classmethod
def execute(cls, bot: Red, query: str, parameters: tuple | None = None) -> List["Moderation"]: def execute(cls, bot: Red, guild_id: int, query: str, parameters: tuple | None = None) -> List["Moderation"]:
from ..utilities.database import connect from ..utilities.database import connect
if not parameters: if not parameters:
parameters = () parameters = ()
@ -215,7 +215,7 @@ class Moderation(AuroraGuildModel):
if results: if results:
cases = [] cases = []
for result in results: for result in results:
case = cls.from_result(bot=bot, result=result) case = cls.from_result(bot=bot, result=result, guild_id=guild_id)
if case.moderation_id != 0: if case.moderation_id != 0:
cases.append(case) cases.append(case)
return cases return cases
@ -228,7 +228,7 @@ class Moderation(AuroraGuildModel):
@classmethod @classmethod
def find_by_id(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation": def find_by_id(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation":
query = f"SELECT * FROM moderation_{guild_id} WHERE moderation_id = ?;" query = f"SELECT * FROM moderation_{guild_id} WHERE moderation_id = ?;"
case = cls.execute(bot=bot, query=query, parameters=(moderation_id,)) case = cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(moderation_id,))
if case: if case:
return case[0] return case[0]
raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!") raise ValueError(f"Case {moderation_id} not found in moderation_{guild_id}!")
@ -240,7 +240,7 @@ class Moderation(AuroraGuildModel):
query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})" query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})"
query += " ORDER BY moderation_id DESC;" query += " ORDER BY moderation_id DESC;"
return cls.execute(bot=bot, query=query, parameters=(target, *types) if types else (target,)) return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(target, *types) if types else (target,))
@classmethod @classmethod
def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, types: list | None = None) -> List["Moderation"]: def find_by_moderator(cls, bot: Red, guild_id: int, moderator: int, types: list | None = None) -> List["Moderation"]:
@ -249,7 +249,7 @@ class Moderation(AuroraGuildModel):
query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})" query += f" AND moderation_type IN ({', '.join(['?' for _ in types])})"
query += " ORDER BY moderation_id DESC;" query += " ORDER BY moderation_id DESC;"
return cls.execute(bot=bot, query=query, parameters=(moderator, *types) if types else (moderator,)) return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=(moderator, *types) if types else (moderator,))
@classmethod @classmethod
def get_all_cases(cls, bot: Red, guild_id: int, types: list | None = None) -> List["Moderation"]: def get_all_cases(cls, bot: Red, guild_id: int, types: list | None = None) -> List["Moderation"]:
@ -257,7 +257,7 @@ class Moderation(AuroraGuildModel):
if types: if types:
query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})" query += f" WHERE moderation_type IN ({', '.join(['?' for _ in types])})"
query += " ORDER BY moderation_id DESC;" query += " ORDER BY moderation_id DESC;"
return cls.execute(bot=bot, query=query, parameters=tuple(iterable=types) if types else None) return cls.execute(bot=bot, guild_id=guild_id, query=query, parameters=tuple(iterable=types) if types else None)
@classmethod @classmethod
def log( def log(