Introduced i18n for /event, /guess, /register and /unregister. Prepared other commands for i18n too

This commit is contained in:
2025-04-27 22:04:14 +02:00
parent 12a88d5a23
commit 9a5edbaa4d
6 changed files with 273 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
from bson.errors import InvalidId
from discord import ApplicationContext, Cog, option, slash_command
from discord.utils import basic_autocomplete
from libbot.i18n import in_every_locale, _
from classes import PycordEvent, PycordGuild, PycordUser
from classes.pycord_bot import PycordBot
@@ -13,17 +14,27 @@ class CogUnregister(Cog):
def __init__(self, bot: PycordBot):
self.bot: PycordBot = bot
# TODO Introduce i18n
@slash_command(
name="unregister",
description="Leave the selected event",
description=_("description", "commands", "unregister"),
description_localizations=in_every_locale("description", "commands", "unregister"),
)
@option(
"event",
description="Name of the event",
description=_("description", "commands", "unregister", "options", "event"),
description_localizations=in_every_locale(
"description", "commands", "unregister", "options", "event"
),
autocomplete=basic_autocomplete(autocomplete_user_registered_events),
)
@option("confirm", description="Confirmation of the operation", required=False)
@option(
"confirm",
description=_("description", "commands", "unregister", "options", "confirm"),
description_localizations=in_every_locale(
"description", "commands", "unregister", "options", "confirm"
),
required=False,
)
async def command_unregister(self, ctx: ApplicationContext, event: str, confirm: bool = False) -> None:
if not (await is_operation_confirmed(ctx, confirm)):
return
@@ -45,7 +56,9 @@ class CogUnregister(Cog):
if user.is_jailed:
# TODO Make a nice message
await ctx.respond("You are jailed and cannot interact with events. Please, contact the administrator.")
await ctx.respond(
"You are jailed and cannot interact with events. Please, contact the administrator."
)
return
if pycord_event._id not in user.registered_event_ids: