Implemented #7

This commit is contained in:
2025-04-25 11:37:44 +02:00
parent d9f563285c
commit fb16fa2bc8
9 changed files with 175 additions and 58 deletions

View File

@@ -1,4 +1,5 @@
from datetime import datetime
from typing import List, Dict, Any
from zoneinfo import ZoneInfo
from bson.errors import InvalidId
@@ -14,11 +15,11 @@ from modules.utils import autocomplete_active_events, autocomplete_event_stages
async def validate_event_status(
ctx: ApplicationContext,
event: PycordEvent,
) -> None:
) -> bool:
if event.is_cancelled:
# TODO Make a nice message
await ctx.respond("This event was cancelled.")
return
return False
if (
event.starts.replace(tzinfo=ZoneInfo("UTC"))
@@ -27,7 +28,9 @@ async def validate_event_status(
):
# TODO Make a nice message
await ctx.respond("Ongoing events cannot be modified.")
return
return False
return True
class Stage(Cog):
@@ -75,7 +78,12 @@ class Stage(Cog):
await ctx.respond("Event was not found.")
return
await validate_event_status(ctx, pycord_event)
if not (await validate_event_status(ctx, pycord_event)):
return
processed_media: List[Dict[str, Any]] = (
[] if media is None else await self.bot.process_attachments([media])
)
event_stage: PycordEventStage = await self.bot.create_event_stage(
event=pycord_event,
@@ -85,7 +93,7 @@ class Stage(Cog):
creator_id=ctx.author.id,
question=question,
answer=answer,
media=[] if media is None else [media.id],
media=[] if media is None else processed_media,
)
# TODO Make a nice message
@@ -140,7 +148,8 @@ class Stage(Cog):
await ctx.respond("Event was not found.")
return
await validate_event_status(ctx, pycord_event)
if not (await validate_event_status(ctx, pycord_event)):
return
try:
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)
@@ -154,11 +163,15 @@ class Stage(Cog):
await ctx.respond("Stage sequence out of range.")
return
processed_media: List[Dict[str, Any]] = (
[] if media is None else await self.bot.process_attachments([media])
)
if not (question is None and answer is None and media is None and remove_media is False):
await event_stage.update(
question=event_stage.question if question is None else question,
answer=event_stage.answer if answer is None else answer,
media=[] if remove_media else (event_stage.media if media is None else [media.id]),
media=([] if remove_media else (event_stage.media if media is None else processed_media)),
)
if order is not None and order - 1 != event_stage.sequence:
@@ -207,7 +220,8 @@ class Stage(Cog):
await ctx.respond("Event was not found.")
return
await validate_event_status(ctx, pycord_event)
if not (await validate_event_status(ctx, pycord_event)):
return
try:
event_stage: PycordEventStage = await self.bot.find_event_stage(stage)