fixed Cog enable
Trying to add localization
This commit is contained in:
96
bot.py
96
bot.py
@@ -31,7 +31,7 @@ intents = disnake.Intents(messages=True,
|
||||
bot = commands.Bot(command_prefix=determine_prefix,
|
||||
intents=intents,
|
||||
reload=True,
|
||||
|
||||
test_guilds=[648126669122568215]
|
||||
)
|
||||
|
||||
|
||||
@@ -48,15 +48,15 @@ async def on_ready():
|
||||
|
||||
@bot.slash_command(
|
||||
name="cog",
|
||||
description="Work with cogs",
|
||||
# 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(
|
||||
# "what_do",
|
||||
# description="Specify what do with cogs",
|
||||
# type=OptionType.string,
|
||||
# required=True,
|
||||
# choices=["load", "unload", "reload", "enable", "disable"]
|
||||
# ),
|
||||
Option(
|
||||
'cog',
|
||||
description="specify cog",
|
||||
@@ -65,27 +65,79 @@ async def on_ready():
|
||||
]
|
||||
)
|
||||
@commands.is_owner()
|
||||
async def slash_cogs(inter: disnake.ApplicationCommandInteraction, what_do, cog: str):
|
||||
await work_with_cogs(what_do, bot, cog)
|
||||
await inter.response.send_message(f'Cog {cog} is {what_do}ed', ephemeral=True)
|
||||
async def slash_cogs(inter: disnake.ApplicationCommandInteraction):
|
||||
"""
|
||||
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')
|
||||
async def _cog_opt(inter: disnake.ApplicationCommandInteraction, what_do, current: str):
|
||||
@slash_cogs.sub_command()
|
||||
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()
|
||||
if what_do == 'enable':
|
||||
_list = await cog_list('./cogs/disabled/')
|
||||
logger.error(_list)
|
||||
else:
|
||||
_list = await cog_list()
|
||||
logger.error(_list)
|
||||
_list = await cog_list(fold='./cogs/')
|
||||
return [choice for choice in _list if current in choice.lower()]
|
||||
|
||||
|
||||
@enable.autocomplete('cog')
|
||||
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()]
|
||||
|
||||
|
||||
@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)
|
||||
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'))
|
||||
|
||||
Reference in New Issue
Block a user