diff options
| author | 2019-06-26 14:37:26 +0100 | |
|---|---|---|
| committer | 2019-06-26 14:37:41 +0100 | |
| commit | c5785a2d1484a98616b0fb8b5a7cb728eb094435 (patch) | |
| tree | 470ace2c509805fb9b723592df196b4e9e0edb46 /src/ModuleManager.py | |
| parent | Update IRCBot `except queue.Empty` comment (diff) | |
| signature | ||
implement @utils.kwarg() magic, use it for command.regex hooks
Diffstat (limited to 'src/ModuleManager.py')
| -rw-r--r-- | src/ModuleManager.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py index 57fbde3b..45866d23 100644 --- a/src/ModuleManager.py +++ b/src/ModuleManager.py @@ -205,12 +205,24 @@ class ModuleManager(object): if not hasattr(module_object, "_name"): module_object._name = definition.name.title() + + # @utils.hook() magic for attribute_name in dir(module_object): attribute = getattr(module_object, attribute_name) - for hook in self._get_magic(attribute, - utils.consts.BITBOT_HOOKS_MAGIC, []): - context_events.on(hook["event"]).hook(attribute, - **hook["kwargs"]) + if inspect.ismethod(attribute): + kwargs = self._get_magic(attribute, + utils.consts.BITBOT_KWARG_MAGIC, []) + kwargs = dict(list(d.items())[0] for d in kwargs) + + for hook in self._get_magic(attribute, + utils.consts.BITBOT_HOOKS_MAGIC, []): + new_kwargs = kwargs.copy() + new_kwargs.update(hook["kwargs"]) + + context_events.on(hook["event"]).hook(attribute, + **new_kwargs) + + # @utils.export() magic for export in self._get_magic(module_object, utils.consts.BITBOT_EXPORTS_MAGIC, []): context_exports.add(export["setting"], export["value"]) |
