2024-05-06 17:23:59 -04:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
from redbot.core.bot import Red
|
|
|
|
|
|
|
|
|
|
|
|
class AuroraBaseModel(BaseModel):
|
|
|
|
"""Base class for all models in Aurora."""
|
|
|
|
model_config = ConfigDict(ignored_types=(Red,), arbitrary_types_allowed=True)
|
|
|
|
bot: Red
|
|
|
|
|
2024-05-06 21:04:08 -04:00
|
|
|
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
|
2024-05-06 17:23:59 -04:00
|
|
|
from aurora.utilities.json import ( # 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)
|
|
|
|
|
|
|
|
class AuroraGuildModel(AuroraBaseModel):
|
|
|
|
"""Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match."""
|
|
|
|
guild_id: int
|
|
|
|
|
2024-05-06 21:04:08 -04:00
|
|
|
def to_json(self, indent: int | None = None, file: Any | None = None, **kwargs):
|
2024-05-06 17:23:59 -04:00
|
|
|
from aurora.utilities.json import ( # 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)
|