Introduced i18n for /event, /guess, /register and /unregister. Prepared other commands for i18n too
This commit is contained in:
@@ -11,6 +11,7 @@ from discord import (
|
||||
)
|
||||
from discord.ext.commands import Cog
|
||||
from discord.utils import basic_autocomplete
|
||||
from libbot.i18n import in_every_locale, _
|
||||
|
||||
from classes import PycordEvent, PycordEventStage, PycordGuild
|
||||
from classes.pycord_bot import PycordBot
|
||||
@@ -28,18 +29,49 @@ class CogEvent(Cog):
|
||||
def __init__(self, bot: PycordBot):
|
||||
self.bot: PycordBot = bot
|
||||
|
||||
# TODO Introduce i18n
|
||||
command_group: SlashCommandGroup = SlashCommandGroup("event", "Event management")
|
||||
command_group: SlashCommandGroup = SlashCommandGroup(
|
||||
"event",
|
||||
description=_("description", "commands", "event"),
|
||||
description_localizations=in_every_locale("description", "commands", "event"),
|
||||
)
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="create",
|
||||
description="Create new event",
|
||||
description=_("description", "commands", "event_create"),
|
||||
description_localizations=in_every_locale("description", "commands", "event_create"),
|
||||
)
|
||||
@option(
|
||||
"name",
|
||||
description=_("description", "commands", "event_create", "options", "name"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_create", "options", "name"
|
||||
),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"start",
|
||||
description=_("description", "commands", "event_create", "options", "start"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_create", "options", "start"
|
||||
),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"end",
|
||||
description=_("description", "commands", "event_create", "options", "end"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_create", "options", "end"
|
||||
),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"thumbnail",
|
||||
description=_("description", "commands", "event_create", "options", "thumbnail"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_create", "options", "thumbnail"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
@option("name", description="Name of the event", required=True)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY HH:MM)", required=True)
|
||||
@option("end", description="Date when the event ends (DD.MM.YYYY HH:MM)", required=True)
|
||||
@option("thumbnail", description="Thumbnail of the event", required=False)
|
||||
async def command_event_create(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
@@ -89,21 +121,52 @@ class CogEvent(Cog):
|
||||
f"Event **{event.name}** has been created and will take place <t:{get_unix_timestamp(event.starts)}:R>."
|
||||
)
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="edit",
|
||||
description="Edit event",
|
||||
description=_("description", "commands", "event_edit"),
|
||||
description_localizations=in_every_locale("description", "commands", "event_edit"),
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
description=_("description", "commands", "event_edit", "options", "event"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_edit", "options", "event"
|
||||
),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("name", description="New name of the event", required=False)
|
||||
@option("start", description="Date when the event starts (DD.MM.YYYY HH:MM)", required=False)
|
||||
@option("end", description="Date when the event ends (DD.MM.YYYY HH:MM)", required=False)
|
||||
@option("thumbnail", description="Thumbnail of the event", required=False)
|
||||
@option(
|
||||
"name",
|
||||
description=_("description", "commands", "event_edit", "options", "name"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_edit", "options", "name"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
@option(
|
||||
"start",
|
||||
description=_("description", "commands", "event_edit", "options", "start"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_edit", "options", "start"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
@option(
|
||||
"end",
|
||||
description=_("description", "commands", "event_edit", "options", "end"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_edit", "options", "end"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
@option(
|
||||
"thumbnail",
|
||||
description=_("description", "commands", "event_edit", "options", "thumbnail"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_edit", "options", "thumbnail"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
async def command_event_edit(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
@@ -139,7 +202,9 @@ class CogEvent(Cog):
|
||||
return
|
||||
|
||||
try:
|
||||
end_date: datetime = pycord_event.ends if end is None else datetime.strptime(end, "%d.%m.%Y %H:%M")
|
||||
end_date: datetime = (
|
||||
pycord_event.ends if end is None else datetime.strptime(end, "%d.%m.%Y %H:%M")
|
||||
)
|
||||
end_date = end_date.replace(tzinfo=guild_timezone)
|
||||
except ValueError:
|
||||
# TODO Make a nice message
|
||||
@@ -167,18 +232,28 @@ class CogEvent(Cog):
|
||||
f"Event **{pycord_event.name}** has been updated and will take place <t:{get_unix_timestamp(pycord_event.starts)}:R>."
|
||||
)
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="cancel",
|
||||
description="Cancel event",
|
||||
description=_("description", "commands", "event_cancel"),
|
||||
description_localizations=in_every_locale("description", "commands", "event_cancel"),
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
description=_("description", "commands", "event_cancel", "options", "event"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_cancel", "options", "event"
|
||||
),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
@option(
|
||||
"confirm",
|
||||
description=_("description", "commands", "event_cancel", "options", "confirm"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_cancel", "options", "confirm"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
async def command_event_cancel(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
@@ -221,14 +296,17 @@ class CogEvent(Cog):
|
||||
# TODO Make a nice message
|
||||
await ctx.respond(f"Event **{pycord_event.name}** was cancelled.")
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="show",
|
||||
description="Show the details about certain event",
|
||||
description=_("description", "commands", "event_show"),
|
||||
description_localizations=in_every_locale("description", "commands", "event_show"),
|
||||
)
|
||||
@option(
|
||||
"event",
|
||||
description="Name of the event",
|
||||
description=_("description", "commands", "event_show", "options", "event"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "event_show", "options", "event"
|
||||
),
|
||||
autocomplete=basic_autocomplete(autocomplete_active_events),
|
||||
required=True,
|
||||
)
|
||||
|
Reference in New Issue
Block a user