Handle extensions not being loaded on reload (needs more debugging)

This commit is contained in:
Zeva Rose 2022-05-03 16:01:05 -06:00
parent 853dbdb80b
commit 44579329af

View file

@ -9,6 +9,7 @@ from types import FunctionType, ModuleType
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
import git import git
from naff.client.errors import ExtensionNotFound
from naff.client.utils.misc_utils import find, find_all from naff.client.utils.misc_utils import find, find_all
from naff.models.naff.application_commands import SlashCommand from naff.models.naff.application_commands import SlashCommand
from naff.models.naff.cog import Cog from naff.models.naff.cog import Cog
@ -160,7 +161,10 @@ async def update(bot: "Client") -> Optional[UpdateResult]:
bot.load_cog(module) bot.load_cog(module)
loaded.append(module) loaded.append(module)
elif len(current_commands[module]) != len(commands): elif len(current_commands[module]) != len(commands):
bot.reload_cog(module) try:
bot.reload_cog(module)
except ExtensionNotFound:
bot.load_cog(module)
reloaded.append(module) reloaded.append(module)
else: else:
for command in commands: for command in commands:
@ -182,15 +186,24 @@ async def update(bot: "Client") -> Optional[UpdateResult]:
# Check if number arguments have changed # Check if number arguments have changed
if len(old_args) != len(new_args): if len(old_args) != len(new_args):
bot.reload_cog(module) try:
bot.reload_cog(module)
except ExtensionNotFound:
bot.load_cog(module)
reloaded.append(module) reloaded.append(module)
elif any(x not in old_arg_names for x in new_arg_names) or any( 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 x not in new_arg_names for x in old_arg_names
): ):
bot.reload_cog(module) try:
bot.reload_cog(module)
except ExtensionNotFound:
bot.load_cog(module)
reloaded.append(module) reloaded.append(module)
elif any(new_args[idx].type != x.type for idx, x in enumerate(old_args)): elif any(new_args[idx].type != x.type for idx, x in enumerate(old_args)):
bot.reload_cog(module) try:
bot.reload_cog(module)
except ExtensionNotFound:
bot.load_cog(module)
reloaded.append(module) reloaded.append(module)
return UpdateResult( return UpdateResult(