WIP: Refactor Aurora (3.0.0) #29

Draft
cswimr wants to merge 347 commits from aurora-pydantic into main
2 changed files with 12 additions and 3 deletions
Showing only changes of commit 08512d0dad - Show all commits

View file

@ -12,16 +12,18 @@ from redbot.core import data_manager
from redbot.core.bot import Red from redbot.core.bot import Red
from ..utilities.logger import logger from ..utilities.logger import logger
from ..utilities.registry import type_registry
from ..utilities.utils import timedelta_to_string from ..utilities.utils import timedelta_to_string
from .base import AuroraGuildModel from .base import AuroraGuildModel
from .change import Change from .change import Change
from .partials import PartialChannel, PartialRole, PartialUser from .partials import PartialChannel, PartialRole, PartialUser
from .type import Type
class Moderation(AuroraGuildModel): class Moderation(AuroraGuildModel):
moderation_id: int moderation_id: int
timestamp: datetime timestamp: datetime
moderation_type: str moderation_type: Type
target_type: str target_type: str
target_id: int target_id: int
moderator_id: int moderator_id: int
@ -125,7 +127,7 @@ class Moderation(AuroraGuildModel):
await self.execute(query, ( await self.execute(query, (
self.timestamp.timestamp(), self.timestamp.timestamp(),
self.moderation_type, self.moderation_type.moderation_type,
self.target_type, self.target_type,
self.moderator_id, self.moderator_id,
self.role_id, self.role_id,
@ -192,11 +194,15 @@ class Moderation(AuroraGuildModel):
else: else:
metadata = {} metadata = {}
moderation_type = str.lower(result[2])
if moderation_type in type_registry:
moderation_type = type_registry[moderation_type]
case = { case = {
"moderation_id": int(result[0]), "moderation_id": int(result[0]),
"guild_id": int(guild_id), "guild_id": int(guild_id),
"timestamp": datetime.fromtimestamp(result[1]), "timestamp": datetime.fromtimestamp(result[1]),
"moderation_type": str(result[2]), "moderation_type": moderation_type,
"target_type": str(result[3]), "target_type": str(result[3]),
"target_id": int(result[4]), "target_id": int(result[4]),
"moderator_id": int(result[5]), "moderator_id": int(result[5]),

View file

@ -5,6 +5,7 @@ from typing import Any
from redbot.core.bot import Red from redbot.core.bot import Red
from ..models.base import AuroraBaseModel from ..models.base import AuroraBaseModel
from ..models.type import Type
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
@ -16,6 +17,8 @@ class JSONEncoder(json.JSONEncoder):
return str(o) return str(o)
case AuroraBaseModel(): case AuroraBaseModel():
return o.dump() return o.dump()
case Type():
return o.moderation_type
case Red(): case Red():
return None return None
case _: case _: