updated lib_Cog test

This commit is contained in:
bacon
2024-03-17 21:34:03 +03:00
parent cb72e48f09
commit 4e535f6580
4 changed files with 25 additions and 22 deletions

View File

@@ -8,6 +8,8 @@ work_with_cogs: loads, reloads and unloads cogs files
"""
from os import listdir, rename
from disnake.ext.commands.interaction_bot_base import InteractionBotBase
from .Logger import logger
@@ -20,27 +22,29 @@ def cog_list(fold: str = './cogs') -> list:
async def work_with_cogs(what_do: str,
bot,
bot: InteractionBotBase,
cog: str | list):
if isinstance(cog, str):
cog = cog.split()
for _filename in cog:
if _filename.endswith('.py'):
_filename = _filename.split('.')[0]
if what_do == "load":
await bot.load_extension(f'cogs.{_filename}')
bot.load_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} loaded')
elif what_do == 'unload':
await bot.unload_extension(f'cogs.{_filename}')
bot.unload_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} unloaded')
elif what_do == 'reload':
await bot.reload_extension(f'cogs.{_filename}')
bot.reload_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} reloaded')
elif what_do == 'disable':
await bot.unload_extension(f'cogs.{_filename}')
bot.unload_extension(f'cogs.{_filename}')
rename(f'cogs/{_filename}.py',
f'cogs/disabled/{_filename}.py')
logger.info(f'Cog {_filename} stopped and disabled')
elif what_do == 'enable':
rename(f'cogs/disabled/{_filename}.py',
f'cogs/{_filename}.py')
await bot.load_extension(f'cogs.{_filename}')
bot.load_extension(f'cogs.{_filename}')
logger.info(f'Cog {_filename} started and enabled')