Improved some messages and prepared them for i18n
This commit is contained in:
@@ -7,5 +7,7 @@ from .autocomplete_utils import (
|
||||
autocomplete_user_registered_events,
|
||||
)
|
||||
from .cache_utils import restore_from_cache
|
||||
from .datetime_utils import get_unix_timestamp
|
||||
from .event_utils import validate_event_validity
|
||||
from .logging_utils import get_logger, get_logging_config
|
||||
from .validation_utils import is_event_status_valid, is_operation_confirmed
|
||||
|
@@ -92,8 +92,6 @@ async def autocomplete_event_stages(ctx: AutocompleteContext) -> List[OptionChoi
|
||||
event_stages: List[OptionChoice] = []
|
||||
|
||||
async for result in col_stages.find(query).sort([("sequence", ASCENDING)]):
|
||||
event_stages.append(
|
||||
OptionChoice(f"{result['sequence']+1} ({result['question']})", str(result["_id"]))
|
||||
)
|
||||
event_stages.append(OptionChoice(f"{result['sequence']+1} ({result['question']})", str(result["_id"])))
|
||||
|
||||
return event_stages
|
||||
|
7
modules/utils/datetime_utils.py
Normal file
7
modules/utils/datetime_utils.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
|
||||
# TODO Add documentation
|
||||
def get_unix_timestamp(date: datetime) -> int:
|
||||
return int((date.replace(tzinfo=ZoneInfo("UTC"))).timestamp())
|
33
modules/utils/validation_utils.py
Normal file
33
modules/utils/validation_utils.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from discord import ApplicationContext
|
||||
|
||||
|
||||
async def is_operation_confirmed(ctx: ApplicationContext, confirm: bool) -> bool:
|
||||
if confirm is None or not confirm:
|
||||
await ctx.respond(ctx.bot._("operation_unconfirmed", "messages", locale=ctx.locale))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def is_event_status_valid(
|
||||
ctx: ApplicationContext,
|
||||
event: "PycordEvent",
|
||||
) -> bool:
|
||||
if event.is_cancelled:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("This event was cancelled.")
|
||||
return False
|
||||
|
||||
if (
|
||||
event.starts.replace(tzinfo=ZoneInfo("UTC"))
|
||||
<= datetime.now(tz=ZoneInfo("UTC"))
|
||||
<= event.ends.replace(tzinfo=ZoneInfo("UTC"))
|
||||
):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Ongoing events cannot be modified.")
|
||||
return False
|
||||
|
||||
return True
|
Reference in New Issue
Block a user