Skip to content

Commit

Permalink
[instacmd] Refactor resume_commands (#193)
Browse files Browse the repository at this point in the history
* refactor resume_commands

* bump version number
  • Loading branch information
Zephyrkul committed Jan 15, 2022
1 parent b8047c6 commit bc6bc2d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions instantcmd/instantcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(self, bot: Red):
bot.loop.create_task(self.resume_commands())

__author__ = ["retke (El Laggron)"]
__version__ = "1.3.1"
__version__ = "1.3.2"

# def get_config_identifier(self, name):
# """
Expand Down Expand Up @@ -131,18 +131,24 @@ async def resume_commands(self):
Load all instant commands made.
This is executed on load with __init__
"""
dev_values = await self.data.dev_values()
for name, code in dev_values.items():
try:
function = self.get_function_from_str(code, name)
except Exception as e:
log.exception("An exception occurred while trying to resume dev value %s", name)
else:
self.bot.add_dev_env_value(name, function)
log.debug(f"Added dev value %s", name)

_commands = await self.data.commands()
for name, command_string in _commands.items():
function = self.get_function_from_str(command_string, name)
self.load_command_or_listener(function)
if self.bot.get_cog("Dev") is None:
return
dev_values = await self.data.dev_values()
for name, code in dev_values.items():
function = self.get_function_from_str(code, name)
self.bot.add_dev_env_value(name, function)
log.debug(f"Added dev value {name}")
try:
function = self.get_function_from_str(command_string, name)
except Exception as e:
log.exception("An exception occurred while trying to resume command %s", name)
else:
self.load_command_or_listener(function)

async def remove_commands(self):
async with self.data.commands() as _commands:
Expand Down

0 comments on commit bc6bc2d

Please sign in to comment.