Introduced i18n to CogEvent

This commit is contained in:
2025-05-03 00:33:49 +02:00
parent fa200ef92d
commit 327dcba544
2 changed files with 41 additions and 29 deletions

View File

@@ -24,7 +24,6 @@ from modules.utils import (
)
# noinspection Mypy
class CogEvent(Cog):
"""Cog with event management commands."""
@@ -98,10 +97,7 @@ class CogEvent(Cog):
start_date: datetime = datetime.strptime(start, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
end_date: datetime = datetime.strptime(end, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
except ValueError:
# TODO Introduce i18n
await ctx.respond(
"Could not parse start and end dates. Please, make sure these are provided in `DD.MM.YYYY HH:MM` format."
)
await ctx.respond(self.bot._("event_dates_parsing_failed", "messages", locale=ctx.locale))
return
if not await validate_event_validity(ctx, name, start_date, end_date, to_utc=True):
@@ -120,9 +116,10 @@ class CogEvent(Cog):
thumbnail=processed_media[0] if thumbnail else None,
)
# TODO Introduce i18n
await ctx.respond(
f"Event **{event.name}** has been created and will take place <t:{get_unix_timestamp(event.starts, to_utc=True)}:R>."
self.bot._("event_created", "messages", locale=ctx.locale).format(
event_name=event.name, start_time=get_unix_timestamp(event.starts, to_utc=True)
)
)
@command_group.command(
@@ -205,10 +202,7 @@ class CogEvent(Cog):
else datetime.strptime(start, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
)
except ValueError:
# TODO Make a nice message
await ctx.respond(
"Could not parse the start date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format."
)
await ctx.respond(self.bot._("event_start_date_parsing_failed", "messages", locale=ctx.locale))
return
try:
@@ -218,10 +212,7 @@ class CogEvent(Cog):
else datetime.strptime(end, "%d.%m.%Y %H:%M").replace(tzinfo=guild_timezone)
)
except ValueError:
# TODO Make a nice message
await ctx.respond(
"Could not parse the end date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format."
)
await ctx.respond(self.bot._("event_end_date_parsing_failed", "messages", locale=ctx.locale))
return
if not await validate_event_validity(
@@ -248,9 +239,11 @@ class CogEvent(Cog):
# TODO Notify participants about time changes
# TODO Make a nice message
await ctx.respond(
f"Event **{pycord_event.name}** has been updated and will take place <t:{get_unix_timestamp(pycord_event.starts, to_utc=True)}:R>."
self.bot._("event_updated", "messages", locale=ctx.locale).format(
event_name=pycord_event.name,
start_time=get_unix_timestamp(pycord_event.starts, to_utc=True),
)
)
@command_group.command(
@@ -309,16 +302,22 @@ class CogEvent(Cog):
or end_date <= datetime.now(tz=ZoneInfo("UTC"))
or start_date <= datetime.now(tz=ZoneInfo("UTC"))
):
# TODO Make a nice message
await ctx.respond("Finished or ongoing events cannot be cancelled.")
await ctx.respond(
self.bot._("event_not_editable", "messages", locale=ctx.locale).format(
event_name=pycord_event.name
)
)
return
await pycord_event.cancel()
# TODO Notify participants about cancellation
# TODO Make a nice message
await ctx.respond(f"Event **{pycord_event.name}** was cancelled.")
await ctx.respond(
self.bot._("event_cancelled", "messages", locale=ctx.locale).format(
event_name=pycord_event.name
)
)
@command_group.command(
name="show",
@@ -346,16 +345,20 @@ class CogEvent(Cog):
stages: List[PycordEventStage] = await self.bot.get_event_stages(pycord_event)
# TODO Make a nice message
stages_string: str = "\n\n".join(
f"**Stage {stage.sequence+1}**\nAnswer: ||{stage.answer}||" for stage in stages
self.bot._("stage_entry", "messages", locale=ctx.locale).format(
sequence=stage.sequence + 1, answer=stage.answer
)
for stage in stages
)
# TODO Show users registered for the event
# TODO Introduce i18n
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}"
event_info_string: str = self.bot._("event_details", "messages", locale=ctx.locale).format(
event_name=pycord_event.name,
start_time=get_unix_timestamp(starts_date),
end_time=get_unix_timestamp(ends_date),
stages=stages_string,
)
chunk_size: int = 2000