Use proper functions to re-sync commands on update

This commit is contained in:
Zeva Rose 2022-05-01 23:00:28 -06:00
parent 56427993fb
commit 4150892245

View file

@ -143,17 +143,17 @@ async def update(bot: "Snake") -> Optional[UpdateResult]:
for module in current_commands.keys():
if module not in new_commands:
logger.debug(f"Module {module} removed after update")
bot.unload_extension(module)
bot.shed_scale(module)
unloaded.append(module)
logger.debug("Checking for new/modified commands")
for module, commands in new_commands.items():
logger.debug(f"Processing {module}")
if module not in current_commands:
bot.load_extension(module)
bot.grow_scale(module)
loaded.append(module)
elif len(current_commands[module]) != len(commands):
bot.reload_extension(module)
bot.regrow_scale(module)
reloaded.append(module)
else:
for command in commands:
@ -175,15 +175,15 @@ async def update(bot: "Snake") -> Optional[UpdateResult]:
# Check if number arguments have changed
if len(old_args) != len(new_args):
bot.reload_extension(module)
bot.regrow_scale(module)
reloaded.append(module)
elif any(x not in old_arg_names for x in new_arg_names) or any(
x not in new_arg_names for x in old_arg_names
):
bot.reload_extension(module)
bot.regrow_scale(module)
reloaded.append(module)
elif any(new_args[idx].type != x.type for idx, x in enumerate(old_args)):
bot.reload_extension(module)
bot.regrow_scale(module)
reloaded.append(module)
return UpdateResult(