aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ModuleManager.py20
-rw-r--r--src/utils/__init__.py5
-rw-r--r--src/utils/consts.py1
3 files changed, 22 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"])
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 4e947c4b..de812f5b 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -184,6 +184,11 @@ def export(setting: str, value: typing.Any):
{"setting": setting, "value": value})
return module
return _export_func
+def kwarg(key: str, value: typing.Any):
+ def _kwarg_func(func):
+ _set_get_append(func, consts.BITBOT_KWARG_MAGIC, {key: value})
+ return func
+ return _kwarg_func
class MultiCheck(object):
def __init__(self,
diff --git a/src/utils/consts.py b/src/utils/consts.py
index f5272cab..0c57b4b0 100644
--- a/src/utils/consts.py
+++ b/src/utils/consts.py
@@ -2,6 +2,7 @@ import typing
from . import _consts_256_color
BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
+BITBOT_KWARG_MAGIC = "__bitbot_kwarg"
BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
class IRCColor(object):