Renamed "en" to "en-US", removed "uk" and made i18n for /config
This commit is contained in:
@@ -9,6 +9,7 @@ from discord import (
|
|||||||
)
|
)
|
||||||
from discord.ext.commands import Cog
|
from discord.ext.commands import Cog
|
||||||
from discord.utils import basic_autocomplete
|
from discord.utils import basic_autocomplete
|
||||||
|
from libbot.i18n import in_every_locale, _
|
||||||
|
|
||||||
from classes import PycordGuild
|
from classes import PycordGuild
|
||||||
from classes.pycord_bot import PycordBot
|
from classes.pycord_bot import PycordBot
|
||||||
@@ -21,25 +22,41 @@ class Config(Cog):
|
|||||||
def __init__(self, bot: PycordBot):
|
def __init__(self, bot: PycordBot):
|
||||||
self.bot: PycordBot = bot
|
self.bot: PycordBot = bot
|
||||||
|
|
||||||
# TODO Introduce i18n
|
command_group: SlashCommandGroup = SlashCommandGroup(
|
||||||
command_group: SlashCommandGroup = SlashCommandGroup("config", "Guild management")
|
name="config",
|
||||||
|
description=_("description", "commands", "config"),
|
||||||
|
description_localizations=in_every_locale("description", "commands", "config"),
|
||||||
|
)
|
||||||
|
|
||||||
# TODO Introduce i18n
|
|
||||||
@command_group.command(
|
@command_group.command(
|
||||||
name="set",
|
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("channel", description="Text channel for admin notifications", required=True)
|
||||||
@option(
|
@option(
|
||||||
"timezone",
|
"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),
|
autocomplete=basic_autocomplete(autocomplete_timezones),
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@option(
|
@option(
|
||||||
"language",
|
"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),
|
autocomplete=basic_autocomplete(autocomplete_languages),
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@@ -56,7 +73,9 @@ class Config(Cog):
|
|||||||
try:
|
try:
|
||||||
timezone_parsed: ZoneInfo = ZoneInfo(timezone)
|
timezone_parsed: ZoneInfo = ZoneInfo(timezone)
|
||||||
except ZoneInfoNotFoundError:
|
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
|
return
|
||||||
|
|
||||||
await guild.update(
|
await guild.update(
|
||||||
@@ -67,44 +86,51 @@ class Config(Cog):
|
|||||||
language=language,
|
language=language,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO Make a nice message
|
await ctx.respond(self.bot._("config_set", "messages", locale=ctx.locale))
|
||||||
await ctx.respond("Okay.")
|
|
||||||
|
|
||||||
# TODO Introduce i18n
|
|
||||||
@command_group.command(
|
@command_group.command(
|
||||||
name="reset",
|
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:
|
async def command_config_reset(self, ctx: ApplicationContext, confirm: bool = False) -> None:
|
||||||
if confirm is None or not confirm:
|
if confirm is None or not confirm:
|
||||||
# TODO Make a nice message
|
await ctx.respond(self.bot._("operation_unconfirmed", "messages", locale=ctx.locale))
|
||||||
await ctx.respond("Operation not confirmed.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||||
|
|
||||||
await guild.purge(self.bot.cache)
|
await guild.purge(self.bot.cache)
|
||||||
|
|
||||||
# TODO Make a nice message
|
await ctx.respond(self.bot._("config_reset", "messages", locale=ctx.locale))
|
||||||
await ctx.respond("Okay.")
|
|
||||||
|
|
||||||
# TODO Introduce i18n
|
|
||||||
@command_group.command(
|
@command_group.command(
|
||||||
name="show",
|
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:
|
async def command_config_show(self, ctx: ApplicationContext) -> None:
|
||||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||||
|
|
||||||
if not guild.is_configured():
|
if not guild.is_configured():
|
||||||
# TODO Make a nice message
|
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
|
||||||
await ctx.respond("Guild is not configured.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# TODO Make a nice message
|
|
||||||
await ctx.respond(
|
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,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"locale": "en",
|
"locale": "en-US",
|
||||||
"debug": false,
|
"debug": false,
|
||||||
"bot": {
|
"bot": {
|
||||||
"owners": [
|
"owners": [
|
||||||
|
44
locale/en-US.json
Normal file
44
locale/en-US.json
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"messages": {
|
||||||
|
"operation_unconfirmed": "Operation not confirmed.",
|
||||||
|
"guild_unconfigured": "Guild is not configured. Please, report this to the administrator.",
|
||||||
|
"guild_unconfigured_admin": "Guild is not configured. Please, configure it using `/config set`.",
|
||||||
|
"timezone_invalid": "Timezone **{timezone}** was not found. Please, select one of the timezones provided by the autocompletion.",
|
||||||
|
"config_set": "Configuration has been updated. You can review it anytime using `/config show`.",
|
||||||
|
"config_reset": "Configuration has been reset. You can update it using `/config set`, otherwise no events can be held.",
|
||||||
|
"config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: {timezone}\nLanguage: {language}"
|
||||||
|
},
|
||||||
|
"commands": {
|
||||||
|
"config": {
|
||||||
|
"description": "Guild management"
|
||||||
|
},
|
||||||
|
"config_set": {
|
||||||
|
"description": "Configure the guild",
|
||||||
|
"options": {
|
||||||
|
"category": {
|
||||||
|
"description": "Category where channels for each user will be created"
|
||||||
|
},
|
||||||
|
"channel": {
|
||||||
|
"description": "Text channel for admin notifications"
|
||||||
|
},
|
||||||
|
"timezone": {
|
||||||
|
"description": "Timezone in which events take place"
|
||||||
|
},
|
||||||
|
"language": {
|
||||||
|
"description": "Language for bot's messages"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config_reset": {
|
||||||
|
"description": "Reset the guild's configuration",
|
||||||
|
"options": {
|
||||||
|
"confirm": {
|
||||||
|
"description": "Confirmation of the operation"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config_show": {
|
||||||
|
"description": "Show the guild's configuration"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"messages": {}
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"messages": {}
|
|
||||||
}
|
|
Reference in New Issue
Block a user