Improved handling of larger event stages

This commit is contained in:
2025-04-28 14:20:06 +02:00
parent c4ebd1b891
commit 2ccdd6406a
8 changed files with 61 additions and 20 deletions

View File

@@ -144,9 +144,13 @@ class PycordBot(LibPycordBot):
first_stage_files: List[File] | None = first_stage.get_media_files()
await user_channel.send(
f"First stage...\n\n{first_stage.question}", files=first_stage_files
)
question_chunks: List[str] = first_stage.get_question_chunked(2000)
question_chunks_length: int = len(question_chunks)
for index, chunk in enumerate(question_chunks):
await user_channel.send(
chunk, files=None if index != question_chunks_length - 1 else first_stage_files
)
# TODO Make a nice message
await self.notify_admins(
@@ -158,7 +162,11 @@ class PycordBot(LibPycordBot):
async def _process_events_end(self) -> None:
# Get events to end
events: List[PycordEvent] = await self._get_events(
{"ends": datetime.now(tz=ZoneInfo("UTC")).replace(second=0, microsecond=0)}
{
"ends": datetime.now(tz=ZoneInfo("UTC")).replace(second=0, microsecond=0),
"is_cancelled": False,
"ended": None,
}
)
# Process each event
@@ -169,8 +177,7 @@ class PycordBot(LibPycordBot):
# TODO Make a nice message
stages_string: str = "\n\n".join(
f"**Stage {stage.sequence+1}**\nQuestion: {stage.question}\nAnswer: ||{stage.answer}||"
for stage in stages
f"**Stage {stage.sequence+1}**\nAnswer: ||{stage.answer}||" for stage in stages
)
# Get list of participants
@@ -189,10 +196,20 @@ class PycordBot(LibPycordBot):
user_channel: TextChannel = guild.get_channel(user.event_channels[str(event._id)])
# TODO Make a nice message
await user_channel.send(
event_ended_string: str = (
f"Event **{event.name}** has ended! Stages and respective answers are listed below.\n\n{stages_string}"
)
chunk_size: int = 2000
event_info_chunks: List[str] = [
event_ended_string[i : i + chunk_size]
for i in range(0, len(event_ended_string), chunk_size)
]
for chunk in event_info_chunks:
await user_channel.send(chunk)
# Lock each participant out
await user.lock_event_channel(guild, event._id, channel=user_channel)