Added more custom exceptions and prepared everything for documentation

This commit is contained in:
2025-04-27 12:39:30 +02:00
parent 6b143d8a2d
commit 638658af75
10 changed files with 146 additions and 53 deletions

View File

@@ -9,6 +9,7 @@ from discord import Bot
from libbot.cache.classes import Cache
from pymongo.results import InsertOneResult
from classes.errors import EventNotFoundError
from modules.database import col_events
from modules.utils import get_logger, restore_from_cache
@@ -70,16 +71,14 @@ class PycordEvent:
)
if db_entry is None:
raise RuntimeError(f"Event {event_id} not found")
# TODO Add a unique exception
# raise EventNotFoundError(event_id)
raise EventNotFoundError(event_id=event_id)
if cache is not None:
cache.set_json(f"{cls.__short_name__}_{event_id}", db_entry)
return cls(**db_entry)
# TODO Add documentation
@classmethod
async def from_name(cls, event_name: str, cache: Optional[Cache] = None) -> "PycordEvent":
# TODO Add sorting by creation date or something.
@@ -87,16 +86,14 @@ class PycordEvent:
db_entry: Dict[str, Any] | None = await cls.__collection__.find_one({"name": event_name})
if db_entry is None:
raise RuntimeError(f"Event with name {event_name} not found")
# TODO Add a unique exception
# raise EventNotFoundError(event_name)
raise EventNotFoundError(event_name=event_name)
if cache is not None:
cache.set_json(f"{cls.__short_name__}_{db_entry['_id']}", db_entry)
return cls(**db_entry)
# TODO Add documentation
@classmethod
async def create(
cls,
@@ -217,6 +214,7 @@ class PycordEvent:
"stage_ids": self.stage_ids,
}
# TODO Add documentation
@staticmethod
def get_defaults() -> Dict[str, Any]:
return {
@@ -232,6 +230,7 @@ class PycordEvent:
"stage_ids": [],
}
# TODO Add documentation
@staticmethod
def get_default_value(key: str) -> Any:
if key not in PycordEvent.get_defaults():