Implemented /stage add (#2)

This commit is contained in:
2025-04-22 20:24:02 +02:00
parent f2a2c3d85f
commit f2c81648fa
4 changed files with 283 additions and 10 deletions

View File

@@ -8,7 +8,7 @@ from bson import ObjectId
from libbot.cache.classes import Cache
from pymongo.results import InsertOneResult
from modules.database import col_events
from modules.database import col_events, col_stages
from modules.logging_utils import get_logger
logger: Logger = get_logger(__name__)
@@ -42,7 +42,7 @@ class PycordEvent:
starts: datetime
ends: datetime
thumbnail_id: str | None
stage_ids: List[int]
stage_ids: List[ObjectId]
@classmethod
async def from_id(cls, event_id: str | ObjectId, cache: Optional[Cache] = None) -> "PycordEvent":
@@ -268,3 +268,12 @@ class PycordEvent:
async def cancel(self, cache: Optional[Cache] = None):
await self._set(cache, cancelled=True)
async def insert_stage(
self, event_stage_id: ObjectId, sequence: int, cache: Optional[Cache] = None
) -> None:
self.stage_ids.insert(sequence, event_stage_id)
await self._set(cache, stage_ids=self.stage_ids)
# TODO Check if this works
await col_stages.update_many({"_id": {"$eq": self.stage_ids[sequence:]}}, {"$inc": {"sequence": 1}})