Trying to add localization
This commit is contained in:
52
bot.py
52
bot.py
@@ -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'))
|
||||
|
||||
@@ -16,18 +16,21 @@ class General(commands.Cog):
|
||||
|
||||
@commands.slash_command(
|
||||
name="info",
|
||||
description="Read list of tracks for user",
|
||||
options=[
|
||||
Option("user", "Specify any user", OptionType.user),
|
||||
]
|
||||
)
|
||||
async def info(self, inter: disnake.ApplicationCommandInteraction, user=None):
|
||||
audio = None
|
||||
"""
|
||||
Shows user info {{SLASH_INFO}}
|
||||
|
||||
Parameters
|
||||
----------
|
||||
:param inter:
|
||||
:param user:
|
||||
:return:
|
||||
"""
|
||||
user = user or inter.author
|
||||
_user = DBReader(inter.guild.id)
|
||||
for r in _user:
|
||||
if r.userid == user.id:
|
||||
audio = r.defaulttracks
|
||||
|
||||
rolelist = [r.mention for r in user.roles if r != inter.guild.default_role]
|
||||
if rolelist:
|
||||
@@ -35,11 +38,6 @@ class General(commands.Cog):
|
||||
else:
|
||||
roles = "Not added any role"
|
||||
|
||||
if audio:
|
||||
audios = "• " + "\n• ".join(sorted(audio.split(", ")))
|
||||
else:
|
||||
audios = "Not selected audio"
|
||||
|
||||
emb = disnake.Embed(
|
||||
title="General information",
|
||||
description=f"General information on server about {user}",
|
||||
@@ -50,9 +48,8 @@ class General(commands.Cog):
|
||||
value=f"Username: {user}\n"
|
||||
f"Nickname: {user.nick}\n"
|
||||
f"Joined at: {user.joined_at.strftime('%A, %B %d %Y @ %H:%M:%S')}", inline=False)
|
||||
emb.add_field(name="Default audio list", value=f"{audios}")
|
||||
emb.add_field(name="Roles list", value=f"{roles}")
|
||||
emb.set_footer(text="Information requested by: {}".format(inter.author.display_name))
|
||||
emb.set_footer(text=f"Information requested by: {inter.author.display_name}")
|
||||
|
||||
await inter.response.send_message(embed=emb, ephemeral=True)
|
||||
|
||||
|
||||
@@ -5,6 +5,6 @@ from yandex_music import Client
|
||||
client = Client(os.getenv('Yandex_Token')).init()
|
||||
|
||||
|
||||
def _search(self, _str: str, _type: str):
|
||||
def _search(_str: str, _type: str):
|
||||
search_result = client.search(_str, type_=_type)
|
||||
pass
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"ENABLES_COG": "Включение кога",
|
||||
"COG_FILE": "Ког Файл"
|
||||
"COG_FILE": "Выберите ког файл",
|
||||
"SLASH_INFO": "Отобрадение информации о пользователе",
|
||||
"SLASH_COG": "Работа с когами(модулями)"
|
||||
}
|
||||
Reference in New Issue
Block a user