Improved handling of larger event stages
This commit is contained in:
@@ -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)
|
||||
|
||||
|
@@ -246,3 +246,7 @@ class PycordEventStage:
|
||||
if len(self.media) == 0
|
||||
else [File(Path(f"data/{media['id']}"), media["filename"]) for media in self.media]
|
||||
)
|
||||
|
||||
# TODO Add documentation
|
||||
def get_question_chunked(self, chunk_size: int) -> List[str]:
|
||||
return [self.question[i : i + chunk_size] for i in range(0, len(self.question), chunk_size)]
|
||||
|
@@ -329,17 +329,25 @@ class CogEvent(Cog):
|
||||
|
||||
# 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
|
||||
)
|
||||
|
||||
# TODO Show users registered for the event
|
||||
|
||||
# TODO Introduce i18n
|
||||
await ctx.respond(
|
||||
event_info_string: str = (
|
||||
f"**Event details**\n\nName: {pycord_event.name}\nStarts: <t:{get_unix_timestamp(starts_date)}>\nEnds: <t:{get_unix_timestamp(ends_date)}>\n\nStages:\n{stages_string}"
|
||||
)
|
||||
|
||||
chunk_size: int = 2000
|
||||
|
||||
event_info_chunks: List[str] = [
|
||||
event_info_string[i : i + chunk_size] for i in range(0, len(event_info_string), chunk_size)
|
||||
]
|
||||
|
||||
for chunk in event_info_chunks:
|
||||
await ctx.respond(chunk)
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
bot.add_cog(CogEvent(bot))
|
||||
|
@@ -96,10 +96,11 @@ class CogGuess(Cog):
|
||||
|
||||
files: List[File] | None = next_stage.get_media_files()
|
||||
|
||||
await ctx.respond(
|
||||
f"Provided answer is correct! Next stage...\n\n{next_stage.question}",
|
||||
files=files,
|
||||
)
|
||||
next_question_chunks: List[str] = next_stage.get_question_chunked(2000)
|
||||
next_question_chunks_length: int = len(next_question_chunks)
|
||||
|
||||
for index, chunk in enumerate(next_question_chunks):
|
||||
await ctx.respond(chunk, files=None if index != next_question_chunks_length - 1 else files)
|
||||
|
||||
await user.set_event_stage(next_stage._id, cache=self.bot.cache)
|
||||
|
||||
|
@@ -112,7 +112,13 @@ class CogRegister(Cog):
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
def setup(bot: PycordBot) -> None:
|
||||
|
@@ -57,6 +57,7 @@ class CogStage(Cog):
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "stage_add", "options", "answer"
|
||||
),
|
||||
max_length=500,
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
@@ -155,6 +156,7 @@ class CogStage(Cog):
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "stage_edit", "options", "answer"
|
||||
),
|
||||
max_length=500,
|
||||
required=False,
|
||||
)
|
||||
@option(
|
||||
|
@@ -6,9 +6,9 @@
|
||||
"timezone_invalid": "Timezone **{timezone}** was not found. Please, select one of the timezones provided by the autocompletion.",
|
||||
"config_set": "Configuration has been updated. You can review it anytime using `/config show`.",
|
||||
"config_reset": "Configuration has been reset. You can update it using `/config set`, otherwise no events can be held.",
|
||||
"config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: {timezone}",
|
||||
"config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: `{timezone}`",
|
||||
"status": "**QuizBot** v{version}\n\nUptime: since <t:{start_time}>",
|
||||
"status_git": "**QuizBot** v{version} (`{commit}`)\n\nUptime: since <t:{start_time}>"
|
||||
"status_git": "**QuizBot** v{version} (`{commit}`)\n\nUptime: up since <t:{start_time}>"
|
||||
},
|
||||
"commands": {
|
||||
"config": {
|
||||
|
@@ -29,7 +29,7 @@ async def autocomplete_active_events(ctx: AutocompleteContext) -> List[OptionCho
|
||||
query: Dict[str, Any] = {
|
||||
"ended": None,
|
||||
"ends": {"$gt": datetime.now(tz=ZoneInfo("UTC"))},
|
||||
"is_cancelled": {"$ne": True},
|
||||
"is_cancelled": False,
|
||||
}
|
||||
|
||||
event_names: List[OptionChoice] = []
|
||||
@@ -63,7 +63,7 @@ async def autocomplete_user_registered_events(ctx: AutocompleteContext) -> List[
|
||||
"registered_events.ended": None,
|
||||
"registered_events.ends": {"$gt": datetime.now(tz=ZoneInfo("UTC"))},
|
||||
"registered_events.starts": {"$gt": datetime.now(tz=ZoneInfo("UTC"))},
|
||||
"registered_events.is_cancelled": {"$ne": True},
|
||||
"registered_events.is_cancelled": False,
|
||||
}
|
||||
},
|
||||
]
|
||||
@@ -93,7 +93,10 @@ async def autocomplete_event_stages(ctx: AutocompleteContext) -> List[OptionChoi
|
||||
|
||||
async for result in col_stages.find(query).sort([("sequence", ASCENDING)]):
|
||||
event_stages.append(
|
||||
OptionChoice(f"{result['sequence']+1} ({result['question']})", str(result["_id"]))
|
||||
OptionChoice(
|
||||
f"{result['sequence']+1} ({result['question'] if len(result['question']) < 50 else result['question'][:47] + '...'})",
|
||||
str(result["_id"]),
|
||||
)
|
||||
)
|
||||
|
||||
return event_stages
|
||||
|
Reference in New Issue
Block a user