Renamed "en" to "en-US", removed "uk" and made i18n for /config

This commit is contained in:
2025-04-25 23:18:49 +02:00
parent eb635952fb
commit 1c2e0fda9f
5 changed files with 94 additions and 30 deletions

View File

@@ -9,6 +9,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 PycordGuild
from classes.pycord_bot import PycordBot
@@ -21,25 +22,41 @@ class Config(Cog):
def __init__(self, bot: PycordBot):
self.bot: PycordBot = bot
# TODO Introduce i18n
command_group: SlashCommandGroup = SlashCommandGroup("config", "Guild management")
command_group: SlashCommandGroup = SlashCommandGroup(
name="config",
description=_("description", "commands", "config"),
description_localizations=in_every_locale("description", "commands", "config"),
)
# TODO Introduce i18n
@command_group.command(
name="set",
description="Configure the guild",
description=_("description", "commands", "config_set"),
description_localizations=in_every_locale("description", "commands", "config_set"),
)
@option(
"category",
description=_("description", "commands", "config_set", "options", "category"),
description_localizations=in_every_locale(
"description", "commands", "config_set", "options", "category"
),
required=True,
)
@option("category", description="Category where channels for each user will be created", required=True)
@option("channel", description="Text channel for admin notifications", required=True)
@option(
"timezone",
description="Timezone in which events take place",
description=_("description", "commands", "config_set", "options", "timezone"),
description_localizations=in_every_locale(
"description", "commands", "config_set", "options", "timezone"
),
autocomplete=basic_autocomplete(autocomplete_timezones),
required=True,
)
@option(
"language",
description="Language for bot's messages",
description=_("description", "commands", "config_set", "options", "language"),
description_localizations=in_every_locale(
"description", "commands", "config_set", "options", "language"
),
autocomplete=basic_autocomplete(autocomplete_languages),
required=True,
)
@@ -56,7 +73,9 @@ class Config(Cog):
try:
timezone_parsed: ZoneInfo = ZoneInfo(timezone)
except ZoneInfoNotFoundError:
await ctx.respond(f"Timezone {timezone} was not found.")
await ctx.respond(
self.bot._("timezone_invalid", "messages", locale=ctx.locale).format(timezone=timezone)
)
return
await guild.update(
@@ -67,44 +86,51 @@ class Config(Cog):
language=language,
)
# TODO Make a nice message
await ctx.respond("Okay.")
await ctx.respond(self.bot._("config_set", "messages", locale=ctx.locale))
# TODO Introduce i18n
@command_group.command(
name="reset",
description="Reset the guild's configuration",
description=_("description", "commands", "config_reset"),
description_localizations=in_every_locale("description", "commands", "config_reset"),
)
@option(
"confirm",
description=_("description", "commands", "config_reset", "options", "confirm"),
description_localizations=in_every_locale(
"description", "commands", "config_reset", "options", "confirm"
),
required=False,
)
@option("confirm", description="Confirmation of the operation", required=False)
async def command_config_reset(self, ctx: ApplicationContext, confirm: bool = False) -> None:
if confirm is None or not confirm:
# TODO Make a nice message
await ctx.respond("Operation not confirmed.")
await ctx.respond(self.bot._("operation_unconfirmed", "messages", locale=ctx.locale))
return
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
await guild.purge(self.bot.cache)
# TODO Make a nice message
await ctx.respond("Okay.")
await ctx.respond(self.bot._("config_reset", "messages", locale=ctx.locale))
# TODO Introduce i18n
@command_group.command(
name="show",
description="Show the guild's configuration",
description=_("description", "commands", "config_show"),
description_localizations=in_every_locale("description", "commands", "config_show"),
)
async def command_config_show(self, ctx: ApplicationContext) -> None:
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
if not guild.is_configured():
# TODO Make a nice message
await ctx.respond("Guild is not configured.")
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
return
# TODO Make a nice message
await ctx.respond(
f"**Guild config**\n\nChannel: <#{guild.channel_id}>\nCategory: <#{guild.category_id}>\nTimezone: {guild.timezone}\nLanguage: {guild.language}"
self.bot._("config_show", "messages", locale=ctx.locale).format(
channel_id=guild.channel_id,
category_id=guild.category_id,
timezone=guild.timezone,
language=guild.language,
)
)