Introduced i18n to utility modules
This commit is contained in:
@@ -11,10 +11,16 @@
|
||||
"event_created": "Event **{event_name}** has been created and will take place <t:{start_time}:R>.",
|
||||
"event_dates_parsing_failed": "Could not parse start and end dates. Please, make sure these are provided in `DD.MM.YYYY HH:MM` format.",
|
||||
"event_details": "**Event details**\n\nName: {event_name}\nStarts: <t:{start_time}>\nEnds: <t:{end_time}>\n\nStages:\n{stages}",
|
||||
"event_end_before_start": "Start date must be before end date",
|
||||
"event_end_date_parsing_failed": "Could not parse the end date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format.",
|
||||
"event_end_past": "End date must not be in the past",
|
||||
"event_is_cancelled": "This event was cancelled.",
|
||||
"event_name_duplicate": "There can only be one active event with the same name",
|
||||
"event_not_editable": "Finished or ongoing events cannot be cancelled.",
|
||||
"event_not_found": "Event was not found.",
|
||||
"event_ongoing_not_editable": "Ongoing events cannot be modified.",
|
||||
"event_start_date_parsing_failed": "Could not parse the start date. Please, make sure it is provided in `DD.MM.YYYY HH:MM` format.",
|
||||
"event_start_past": "Start date must not be in the past",
|
||||
"event_updated": "Event **{event_name}** has been updated and will take place <t:{start_time}:R>.",
|
||||
"guess_completed_event": "Congratulations! You have completed the event!",
|
||||
"guess_incorrect_channel": "Usage outside own event channel is not allowed.",
|
||||
|
@@ -6,6 +6,7 @@ from bson import ObjectId
|
||||
from discord import (
|
||||
ApplicationContext,
|
||||
)
|
||||
from libbot.i18n import _
|
||||
|
||||
from modules.database import col_events
|
||||
|
||||
@@ -22,18 +23,15 @@ async def validate_event_validity(
|
||||
end_date_internal: datetime = end_date.astimezone(ZoneInfo("UTC")) if to_utc else end_date
|
||||
|
||||
if start_date_internal < datetime.now(tz=ZoneInfo("UTC")):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Start date must not be in the past")
|
||||
await ctx.respond(_("event_start_past", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
if end_date_internal < datetime.now(tz=ZoneInfo("UTC")):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("End date must not be in the past")
|
||||
await ctx.respond(_("event_end_past", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
if start_date_internal >= end_date_internal:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Start date must be before end date")
|
||||
await ctx.respond(_("event_end_before_start", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
# TODO Add validation for concurrent events.
|
||||
@@ -49,8 +47,7 @@ async def validate_event_validity(
|
||||
query["_id"] = {"$ne": event_id}
|
||||
|
||||
if (await col_events.find_one(query)) is not None:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("There can only be one active event with the same name")
|
||||
await ctx.respond(_("event_name_duplicate", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@@ -2,6 +2,7 @@ from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from discord import ApplicationContext
|
||||
from libbot.i18n import _
|
||||
|
||||
|
||||
async def is_operation_confirmed(ctx: ApplicationContext, confirm: bool) -> bool:
|
||||
@@ -17,8 +18,7 @@ async def is_event_status_valid(
|
||||
event: "PycordEvent",
|
||||
) -> bool:
|
||||
if event.is_cancelled:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("This event was cancelled.")
|
||||
await ctx.respond(_("event_is_cancelled", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
if (
|
||||
@@ -26,8 +26,7 @@ async def is_event_status_valid(
|
||||
<= datetime.now(tz=ZoneInfo("UTC"))
|
||||
<= event.ends.replace(tzinfo=ZoneInfo("UTC"))
|
||||
):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Ongoing events cannot be modified.")
|
||||
await ctx.respond(_("event_ongoing_not_editable", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
Reference in New Issue
Block a user