diff --git a/mmpy_bot/bot.py b/mmpy_bot/bot.py index 0eb60082..7e3c352d 100644 --- a/mmpy_bot/bot.py +++ b/mmpy_bot/bot.py @@ -76,18 +76,25 @@ def init_plugins(self): def _load_plugins(plugin): logger.info('loading plugin "%s"', plugin) path_name = None + # try to load root package as module first + PluginsManager._load_module(plugin) + # load modules in this plugin package for mod in plugin.split('.'): if path_name is not None: path_name = [path_name] _, path_name, _ = imp.find_module(mod, path_name) for py_file in glob('{}/[!_]*.py'.format(path_name)): module = '.'.join((plugin, os.path.split(py_file)[-1][:-3])) - try: - _module = importlib.import_module(module) - if hasattr(_module, 'on_init'): - _module.on_init() - except Exception as err: - logger.exception(err) + PluginsManager._load_module(module) + + @staticmethod + def _load_module(module): + try: + _module = importlib.import_module(module) + if hasattr(_module, 'on_init'): + _module.on_init() + except Exception as err: + logger.exception(err) def get_plugins(self, category, text): has_matching_plugin = False