diff options
| author | khazhyk <[email protected]> | 2017-07-03 20:38:21 -0700 |
|---|---|---|
| committer | khazhyk <[email protected]> | 2017-07-03 20:56:04 -0700 |
| commit | 6c01250c39c0d58e5e4b41fe1edd7179fd8a6275 (patch) | |
| tree | ea10f268a557d1ca057cfd65a3f07cd790e26897 | |
| parent | [commands] clean up remove_cog documentation (diff) | |
| download | discord.py-6c01250c39c0d58e5e4b41fe1edd7179fd8a6275.tar.xz discord.py-6c01250c39c0d58e5e4b41fe1edd7179fd8a6275.zip | |
[commands] fix unloading incorrect cogs
unload_extension would incorrectly unload cogs/listeners
of other extensions if the name of one was a prefix of
another.
| -rw-r--r-- | discord/ext/commands/bot.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index 3a488a41..85b8d134 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -88,6 +88,9 @@ _mentions_transforms = { _mention_pattern = re.compile('|'.join(_mentions_transforms.keys())) +def _is_submodule(parent, child): + return parent == child or child.startswith(parent + ".") + @asyncio.coroutine def _default_help_command(ctx, *commands : str): """Shows this message.""" @@ -731,12 +734,12 @@ class BotBase(GroupMixin): # remove the cogs registered from the module for cogname, cog in self.cogs.copy().items(): - if cog.__module__.startswith(lib_name): + if _is_submodule(lib_name, cog.__module__): self.remove_cog(cogname) # first remove all the commands from the module for cmd in self.all_commands.copy().values(): - if cmd.module.startswith(lib_name): + if _is_submodule(lib_name, cmd.module): if isinstance(cmd, GroupMixin): cmd.recursively_remove_all_commands() self.remove_command(cmd.name) @@ -745,7 +748,7 @@ class BotBase(GroupMixin): for event_list in self.extra_events.copy().values(): remove = [] for index, event in enumerate(event_list): - if event.__module__.startswith(lib_name): + if _is_submodule(lib_name, event.__module__): remove.append(index) for index in reversed(remove): |