Skip to content

Commit

Permalink
enable loading single module plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
seLain committed Jan 31, 2019
1 parent f14e662 commit fabc6ff
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mmpy_bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fabc6ff

Please sign in to comment.