import logging from dataclasses import dataclass from typing import Literal, Union from bson import ObjectId from discord import Thread from classes.enums import MemberStatus from classes.errors import MemberNotFoundError from classes.pycordcheck import PycordCheck from modules.database import col_members logger = logging.getLogger(__name__) @dataclass class PycordMember: """Dataclass of DB entry of a member""" __slots__ = ("_id", "id", "guild", "status") _id: ObjectId id: int guild: ObjectId status: Literal[ MemberStatus.VERIFIED, MemberStatus.UNVERIFIED, MemberStatus.FAILED, MemberStatus.ADDITIONAL, ] @classmethod async def find(cls, id: Union[int, ObjectId], guild: ObjectId): """Find a member in a database. ### Args: * id (`Union[int, ObjectId]`): Member's Discord ID * guild (`ObjectId`): Discord guild's database ID ### Raises: * `MemberNotFoundError`: Raised when member entry after insertion could not be found. ### Returns: * `PycordMember`: Member with its database data. """ db_entry = await col_members.find_one( ( {"id": id, "guild": guild} if isinstance(id, int) else {"_id": id, "guild": guild} ) ) if db_entry is None: raise MemberNotFoundError(id, guild) return cls(**db_entry) @classmethod async def create( cls, id: int, guild: ObjectId, status: Literal[ MemberStatus.VERIFIED, MemberStatus.UNVERIFIED, MemberStatus.FAILED, MemberStatus.ADDITIONAL, ], ): pass async def get_check(self, guild: ObjectId) -> PycordCheck: pass async def set_status( self, status: Literal[ MemberStatus.VERIFIED, MemberStatus.UNVERIFIED, MemberStatus.FAILED, MemberStatus.ADDITIONAL, ], ) -> Union[Thread, None]: pass