aboutsummaryrefslogtreecommitdiff
path: root/src/ModuleManager.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-07-26 11:58:06 +0100
committerGravatar jesopo2019-07-26 11:58:06 +0100
commit77dfc765910ccdebb2816cb65705e67016f80a1f (patch)
treeab94d5cbdc3cd2552a5825cf752d6e3a2b656e59 /src/ModuleManager.py
parent8ball.py -> eightball.py (diff)
signature
switch to function/module magic being a single object
Diffstat (limited to 'src/ModuleManager.py')
-rw-r--r--src/ModuleManager.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index 45866d23..2b1de97d 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -209,23 +209,17 @@ class ModuleManager(object):
# @utils.hook() magic
for attribute_name in dir(module_object):
attribute = getattr(module_object, attribute_name)
- if inspect.ismethod(attribute):
- kwargs = self._get_magic(attribute,
- utils.consts.BITBOT_KWARG_MAGIC, [])
- kwargs = dict(list(d.items())[0] for d in kwargs)
+ if inspect.ismethod(attribute) and utils.has_magic(attribute):
+ magic = utils.get_magic(attribute)
- 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)
+ for hook, kwargs in magic.get_hooks():
+ context_events.on(hook).hook(attribute, **dict(kwargs))
# @utils.export() magic
- for export in self._get_magic(module_object,
- utils.consts.BITBOT_EXPORTS_MAGIC, []):
- context_exports.add(export["setting"], export["value"])
+ if utils.has_magic(module_object):
+ magic = utils.get_magic(module_object)
+ for key, value in magic.get_exports():
+ context_exports.add(key, value)
if definition.name in self.modules:
raise ModuleNameCollisionException("Module name '%s' "