fix(aurora): reverted previous change, instead using pydantic's ConfigDicts to resolve the error I was encountering previously
This commit is contained in:
parent
a7d8f452d1
commit
6a7758e8f9
3 changed files with 14 additions and 12 deletions
|
@ -1,8 +1,8 @@
|
|||
from datetime import datetime, timedelta
|
||||
from typing import Any, ClassVar, Dict, List, Literal, Optional, Union
|
||||
from typing import Any, Dict, List, Literal, Optional, Union
|
||||
|
||||
from discord import Forbidden, HTTPException, InvalidData, NotFound
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from redbot.core.bot import Red
|
||||
|
||||
from aurora.utilities.utils import generate_dict
|
||||
|
@ -10,15 +10,15 @@ from aurora.utilities.utils import generate_dict
|
|||
|
||||
class AuroraBaseModel(BaseModel):
|
||||
"""Base class for all models in Aurora."""
|
||||
bot: ClassVar[Red]
|
||||
model_config = ConfigDict(ignored_types=(Red,))
|
||||
bot: Red
|
||||
|
||||
def to_json(self, indent: int = None, file: Any = None, **kwargs):
|
||||
from aurora.utilities.json 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(BaseModel):
|
||||
"""Base class that includes a guild_id attribute, and a modified to_json() method to match."""
|
||||
bot: ClassVar[Red]
|
||||
class AuroraGuildModel(AuroraBaseModel):
|
||||
"""Subclass of AuroraBaseModel that includes a guild_id attribute, and a modified to_json() method to match."""
|
||||
guild_id: int
|
||||
|
||||
def to_json(self, indent: int = None, file: Any = None, **kwargs):
|
||||
|
|
|
@ -2,13 +2,17 @@
|
|||
from datetime import datetime, timedelta
|
||||
from typing import Union
|
||||
|
||||
from discord import Color, Embed, Guild, Interaction, InteractionMessage, Member, Role, User
|
||||
from discord import (Color, Embed, Guild, Interaction, InteractionMessage,
|
||||
Member, Role, User)
|
||||
from redbot.core import commands
|
||||
from redbot.core.utils.chat_formatting import bold, box, error, humanize_timedelta, warning
|
||||
from redbot.core.utils.chat_formatting import (bold, box, error,
|
||||
humanize_timedelta, warning)
|
||||
|
||||
from aurora.models import Moderation
|
||||
from aurora.utilities.config import config
|
||||
from aurora.utilities.utils import fetch_channel_dict, fetch_user_dict, get_bool_emoji, get_next_case_number, get_pagesize_str
|
||||
from aurora.utilities.utils import (fetch_channel_dict, fetch_user_dict,
|
||||
get_bool_emoji, get_next_case_number,
|
||||
get_pagesize_str)
|
||||
|
||||
|
||||
async def message_factory(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import json
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from aurora.models import AuroraBaseModel, AuroraGuildModel
|
||||
from aurora.models import AuroraBaseModel
|
||||
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
|
@ -12,8 +12,6 @@ class JSONEncoder(json.JSONEncoder):
|
|||
return str(o)
|
||||
if isinstance(o, AuroraBaseModel):
|
||||
return o.to_json()
|
||||
if isinstance(o, AuroraGuildModel):
|
||||
return o.to_json()
|
||||
return super().default(o)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue