WIP: Moderation type registry #26

Closed
cswimr wants to merge 146 commits from aurora-3rd-party into main
2 changed files with 7 additions and 9 deletions
Showing only changes of commit 904fd1c914 - Show all commits

View file

@ -10,8 +10,7 @@ class AuroraBaseModel(BaseModel):
bot: Red bot: Red
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs): def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
from aurora.utilities.json import ( # pylint: disable=cyclic-import from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
dump, dumps)
return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs) return dump(self.model_dump(exclude={"bot"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot"}), indent=indent, **kwargs)
class AuroraGuildModel(AuroraBaseModel): class AuroraGuildModel(AuroraBaseModel):
@ -19,6 +18,5 @@ class AuroraGuildModel(AuroraBaseModel):
guild_id: int guild_id: int
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs): def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
from aurora.utilities.json import ( # pylint: disable=cyclic-import from ..utilities.json import dump, dumps # pylint: disable=cyclic-import
dump, dumps)
return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs) return dump(self.model_dump(exclude={"bot", "guild_id"}), file, indent=indent, **kwargs) if file else dumps(self.model_dump(exclude={"bot", "guild_id"}), indent=indent, **kwargs)

View file

@ -114,8 +114,8 @@ class Moderation(AuroraGuildModel):
self.update() self.update()
def update(self): def update(self):
from aurora.utilities.database import connect from ..utilities.database import connect
from aurora.utilities.json import dumps from ..utilities.json import dumps
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:
@ -199,7 +199,7 @@ class Moderation(AuroraGuildModel):
@classmethod @classmethod
def from_sql(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation": def from_sql(cls, bot: Red, moderation_id: int, guild_id: int) -> "Moderation":
from aurora.utilities.database import connect from ..utilities.database import connect
query = f"SELECT * FROM moderation_{guild_id} WHERE moderation_id = ?;" query = f"SELECT * FROM moderation_{guild_id} WHERE moderation_id = ?;"
with connect() as database: with connect() as database:
@ -234,8 +234,8 @@ class Moderation(AuroraGuildModel):
changes: list | None = None, changes: list | None = None,
metadata: dict | None = None, metadata: dict | None = None,
) -> "Moderation": ) -> "Moderation":
from aurora.utilities.database import connect from ..utilities.database import connect
from aurora.utilities.json import dumps from ..utilities.json import dumps
if not timestamp: if not timestamp:
timestamp = datetime.fromtimestamp(time()) timestamp = datetime.fromtimestamp(time())
elif not isinstance(timestamp, datetime): elif not isinstance(timestamp, datetime):