from dataclasses import dataclass from typing import Dict, Any, Optional from bson import ObjectId from libbot.cache.classes import Cache @dataclass class PycordGuild: _id: ObjectId id: int def __init__(self) -> None: raise NotImplementedError() @classmethod async def from_id( cls, guild_id: int, allow_creation: bool = True, cache: Optional[Cache] = None ) -> "PycordGuild": """Find guild in database and create new record if guild does not exist. Args: guild_id (int): User's Discord ID allow_creation (:obj:`bool`, optional): Create new guild record if none found in the database cache (:obj:`Cache`, optional): Cache engine to get the cache from Returns: PycordGuild: User object Raises: GuildNotFoundError: User was not found and creation was not allowed """ raise NotImplementedError() def to_dict(self, json_compatible: bool = False) -> Dict[str, Any]: """Convert PycordGuild object to a JSON representation. Args: json_compatible (bool): Whether the JSON-incompatible objects like ObjectId need to be converted Returns: Dict[str, Any]: JSON representation of PycordGuild """ return { "_id": self._id if not json_compatible else str(self._id), "id": self.id, }