Trying to add localization

This commit is contained in:
bacon
2024-03-09 17:04:18 +03:00
parent 75869de1cd
commit 3bd30239ae
4 changed files with 49 additions and 32 deletions

52
bot.py
View File

@@ -4,7 +4,7 @@ import os
import disnake
from dotenv import load_dotenv
from disnake import OptionType, Option
from disnake import OptionType, Option, Localized
from disnake.ext import commands
from __init__ import version_info as ver, __version__
from lib.CogsPrep import work_with_cogs, cog_list
@@ -33,7 +33,8 @@ bot = commands.Bot(command_prefix=determine_prefix,
reload=True,
test_guilds=[648126669122568215]
)
bot.i18n.load(f"{os.path.dirname(__file__)}/locale/")
logger.info(f"{os.path.dirname(__file__)}/locale/")
asyncio.run(work_with_cogs('load', bot, asyncio.run(cog_list())))
@@ -48,15 +49,7 @@ async def on_ready():
@bot.slash_command(
name="cog",
# description="Work with cogs",
options=[
# Option(
# "what_do",
# description="Specify what do with cogs",
# type=OptionType.string,
# required=True,
# choices=["load", "unload", "reload", "enable", "disable"]
# ),
Option(
'cog',
description="specify cog",
@@ -67,24 +60,22 @@ async def on_ready():
@commands.is_owner()
async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
"""
Working with cogs (modules)
Working with cogs (modules) {{SLASH_COG}}
Parameters
----------
:param cog: Select cogfile
:param inter:
"""
# await work_with_cogs(what_do, bot, cog)
# await inter.response.send_message(f'Cog {cog} is {what_do}ed', ephemeral=True)
pass
@slash_cogs.sub_command()
@slash_cogs.sub_command(description=Localized("Enables Cog", key="ENABLES_COG"))
async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
"""
Enables Cog {{ENABLES_COG}}
Parameters
----------
:param inter:
:param cog: Select Cogfile {{COG_FILE}}
"""
await work_with_cogs('enable', bot, cog)
@@ -93,24 +84,52 @@ async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
@slash_cogs.sub_command(description='Disables Cog')
async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
"""
Parameters
----------
:param inter:
:param cog: Select Cogfile {{COG_FILE}}
"""
await work_with_cogs('disable', bot, cog)
await inter.response.send_message(f'Cog {cog} is disabled', ephemeral=True)
@slash_cogs.sub_command(description='Loads Cog')
async def load(inter: disnake.ApplicationCommandInteraction, cog: str):
"""
Parameters
----------
:param inter:
:param cog: Select Cogfile {{COG_FILE}}
"""
await work_with_cogs('load', bot, cog)
await inter.response.send_message(f'Cog {cog} is loaded', ephemeral=True)
@slash_cogs.sub_command(description='Unloads Cog')
async def unload(inter: disnake.ApplicationCommandInteraction, cog: str):
"""
Parameters
----------
:param inter:
:param cog: Select Cogfile {{COG_FILE}}
"""
await work_with_cogs('unload', bot, cog)
await inter.response.send_message(f'Cog {cog} is unload', ephemeral=True)
@slash_cogs.sub_command(description='Reloads Cog')
async def reload(inter: disnake.ApplicationCommandInteraction, cog: str):
"""
Parameters
----------
:param inter:
:param cog: Select Cogfile {{COG_FILE}}
"""
await work_with_cogs('reload', bot, cog)
await inter.response.send_message(f'Cog {cog} is reloaded', ephemeral=True)
@@ -139,5 +158,4 @@ async def cogs_error(inter: disnake.ApplicationCommandInteraction):
logger.error(f'User {inter.author} tries to use cogs func')
bot.i18n.load("locale/")
bot.run(os.getenv('TOKEN'))