fixed Cog enable
Trying to add localization
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,7 +2,6 @@
|
|||||||
/audio/*/
|
/audio/*/
|
||||||
/.idea
|
/.idea
|
||||||
/user.db
|
/user.db
|
||||||
*.json
|
|
||||||
*.pyc
|
*.pyc
|
||||||
/.run/
|
/.run/
|
||||||
/.env
|
/.env
|
||||||
@@ -10,3 +9,4 @@
|
|||||||
/venv/
|
/venv/
|
||||||
/fun_and_admin_bot.egg-info/
|
/fun_and_admin_bot.egg-info/
|
||||||
/.YMcache/
|
/.YMcache/
|
||||||
|
config.json
|
||||||
96
bot.py
96
bot.py
@@ -31,7 +31,7 @@ intents = disnake.Intents(messages=True,
|
|||||||
bot = commands.Bot(command_prefix=determine_prefix,
|
bot = commands.Bot(command_prefix=determine_prefix,
|
||||||
intents=intents,
|
intents=intents,
|
||||||
reload=True,
|
reload=True,
|
||||||
|
test_guilds=[648126669122568215]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -48,15 +48,15 @@ async def on_ready():
|
|||||||
|
|
||||||
@bot.slash_command(
|
@bot.slash_command(
|
||||||
name="cog",
|
name="cog",
|
||||||
description="Work with cogs",
|
# description="Work with cogs",
|
||||||
options=[
|
options=[
|
||||||
Option(
|
# Option(
|
||||||
"what_do",
|
# "what_do",
|
||||||
description="Specify what do with cogs",
|
# description="Specify what do with cogs",
|
||||||
type=OptionType.string,
|
# type=OptionType.string,
|
||||||
required=True,
|
# required=True,
|
||||||
choices=["load", "unload", "reload", "enable", "disable"]
|
# choices=["load", "unload", "reload", "enable", "disable"]
|
||||||
),
|
# ),
|
||||||
Option(
|
Option(
|
||||||
'cog',
|
'cog',
|
||||||
description="specify cog",
|
description="specify cog",
|
||||||
@@ -65,27 +65,79 @@ async def on_ready():
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def slash_cogs(inter: disnake.ApplicationCommandInteraction, what_do, cog: str):
|
async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
|
||||||
await work_with_cogs(what_do, bot, cog)
|
"""
|
||||||
await inter.response.send_message(f'Cog {cog} is {what_do}ed', ephemeral=True)
|
Working with cogs (modules)
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
:param cog: Select cogfile
|
||||||
|
"""
|
||||||
|
# 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.autocomplete('cog')
|
@slash_cogs.sub_command()
|
||||||
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, what_do, current: str):
|
async def enable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
|
"""
|
||||||
|
Enables Cog {{ENABLES_COG}}
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
:param cog: Select Cogfile {{COG_FILE}}
|
||||||
|
"""
|
||||||
|
await work_with_cogs('enable', bot, cog)
|
||||||
|
await inter.response.send_message(f'Cog {cog} is enabled', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
@slash_cogs.sub_command(description='Disables Cog')
|
||||||
|
async def disable(inter: disnake.ApplicationCommandInteraction, cog: str):
|
||||||
|
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):
|
||||||
|
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):
|
||||||
|
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):
|
||||||
|
await work_with_cogs('reload', bot, cog)
|
||||||
|
await inter.response.send_message(f'Cog {cog} is reloaded', ephemeral=True)
|
||||||
|
|
||||||
|
|
||||||
|
@disable.autocomplete('cog')
|
||||||
|
@unload.autocomplete('cog')
|
||||||
|
@load.autocomplete('cog')
|
||||||
|
@reload.autocomplete('cog')
|
||||||
|
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str):
|
||||||
current = current.lower()
|
current = current.lower()
|
||||||
if what_do == 'enable':
|
_list = await cog_list(fold='./cogs/')
|
||||||
_list = await cog_list('./cogs/disabled/')
|
return [choice for choice in _list if current in choice.lower()]
|
||||||
logger.error(_list)
|
|
||||||
else:
|
|
||||||
_list = await cog_list()
|
@enable.autocomplete('cog')
|
||||||
logger.error(_list)
|
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, current: str):
|
||||||
|
current = current.lower()
|
||||||
|
_list = await cog_list(fold='./cogs/disabled/')
|
||||||
|
logger.info(_list)
|
||||||
return [choice for choice in _list if current in choice.lower()]
|
return [choice for choice in _list if current in choice.lower()]
|
||||||
|
|
||||||
|
|
||||||
@slash_cogs.error
|
@slash_cogs.error
|
||||||
async def cogs_error(inter: disnake.ApplicationCommandInteraction, what_do):
|
async def cogs_error(inter: disnake.ApplicationCommandInteraction):
|
||||||
await inter.response.send_message('Error', ephemeral=True)
|
await inter.response.send_message('Error', ephemeral=True)
|
||||||
logger.error(f'User {inter.author} tries to use cogs func\n{what_do}\n')
|
logger.error(f'User {inter.author} tries to use cogs func')
|
||||||
|
|
||||||
|
|
||||||
|
bot.i18n.load("locale/")
|
||||||
bot.run(os.getenv('TOKEN'))
|
bot.run(os.getenv('TOKEN'))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from disnake.ext import commands
|
|||||||
from .Logger import logger
|
from .Logger import logger
|
||||||
|
|
||||||
|
|
||||||
async def cog_list(fold='./cogs') -> List[str]:
|
async def cog_list(fold: str = './cogs') -> List[str]:
|
||||||
cogs_list = []
|
cogs_list = []
|
||||||
for _filename in listdir(fold):
|
for _filename in listdir(fold):
|
||||||
if _filename.endswith('.py'):
|
if _filename.endswith('.py'):
|
||||||
@@ -28,19 +28,8 @@ async def work_with_cogs(what_do, bot: commands.Bot, cog):
|
|||||||
cog = cog.split()
|
cog = cog.split()
|
||||||
for _filename in cog:
|
for _filename in cog:
|
||||||
if what_do == "load":
|
if what_do == "load":
|
||||||
try:
|
|
||||||
bot.load_extension(f'cogs.{_filename}')
|
bot.load_extension(f'cogs.{_filename}')
|
||||||
logger.info(f'Loaded cog {_filename}')
|
logger.info(f'Loaded cog {_filename}')
|
||||||
|
|
||||||
except commands.ExtensionNotFound:
|
|
||||||
logger.error(f"Error: {_filename} couldn't be find to load.")
|
|
||||||
|
|
||||||
except commands.ExtensionFailed as error:
|
|
||||||
logger.error(f'Error: {_filename} failed to load properly.\n\t{error}\n\n{traceback.format_exc()}')
|
|
||||||
|
|
||||||
except commands.ExtensionError:
|
|
||||||
logger.error(f'Error: unknown error with {_filename}')
|
|
||||||
|
|
||||||
elif what_do == 'unload':
|
elif what_do == 'unload':
|
||||||
bot.unload_extension(f'cogs.{_filename}')
|
bot.unload_extension(f'cogs.{_filename}')
|
||||||
logger.info(f'Cog {_filename} unloaded')
|
logger.info(f'Cog {_filename} unloaded')
|
||||||
|
|||||||
4
locale/ru.json
Normal file
4
locale/ru.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"ENABLES_COG": "Включение кога",
|
||||||
|
"COG_FILE": "Ког Файл"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user