From c5785a2d1484a98616b0fb8b5a7cb728eb094435 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 26 Jun 2019 14:37:26 +0100 Subject: implement @utils.kwarg() magic, use it for command.regex hooks --- src/ModuleManager.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/ModuleManager.py') 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"]) -- cgit v1.3.1-10-gc9f91