aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2020-02-19 17:22:37 +0000
committerGravatar jesopo2020-02-19 17:22:37 +0000
commit70db97f64e0d6dbdd60f4d6d147d11c5b6b6a204 (patch)
tree353f18c924b00683d7565dd6699360e4e0bc4d78
parentshow when a badge was updated, not added, by "!badge add" (diff)
signature
support @utils.export on functions, to export those functions
-rw-r--r--modules/coins.py7
-rw-r--r--src/ModuleManager.py16
-rw-r--r--src/utils/decorators.py11
3 files changed, 17 insertions, 17 deletions
diff --git a/modules/coins.py b/modules/coins.py
index 1ea228c3..4f366500 100644
--- a/modules/coins.py
+++ b/modules/coins.py
@@ -39,10 +39,6 @@ class CoinParseException(Exception):
pass
class Module(ModuleManager.BaseModule):
- def on_load(self):
- self.exports.add("command-spec.coins", self._coins_spec)
- self.exports.add("command-spec.coinsmany", self._coins_many_spec)
-
def _coin_spec_parse(self, word):
try:
out = decimal.Decimal(word)
@@ -54,11 +50,14 @@ class Module(ModuleManager.BaseModule):
else:
raise utils.parse.SpecTypeError(
"Please provide a positive coin amount")
+
+ @utils.export("command-spec.coins")
def _coins_spec(self, server, channel, user, args):
if args:
return self._coin_spec_parse(args[0]), 1
else:
raise utils.parse.SpecTypeError("No coin amount provided")
+ @utils.export("command-spec.coinsmany")
def _coins_many_spec(self, server, channel, user, args):
out = []
for arg in args:
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index b8dcd107..a43181fe 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -256,7 +256,13 @@ class ModuleManager(object):
module_title = (getattr(module_object, "_name", None) or
definition.name.title())
- # @utils.hook() magic
+ # per-module @export magic
+ if utils.decorators.has_magic(module_object):
+ magic = utils.decorators.get_magic(module_object)
+ for key, value in magic.get_exports():
+ context_exports.add(key, value)
+
+ # per-function @hook/@export magic
for attribute_name in dir(module_object):
attribute = getattr(module_object, attribute_name)
if (inspect.ismethod(attribute) and
@@ -265,12 +271,8 @@ class ModuleManager(object):
for hook, kwargs in magic.get_hooks():
context_events.on(hook)._hook(attribute, kwargs=kwargs)
-
- # @utils.export() magic
- if utils.decorators.has_magic(module_object):
- magic = utils.decorators.get_magic(module_object)
- for key, value in magic.get_exports():
- context_exports.add(key, value)
+ for key, value in magic.get_exports():
+ context_exports.add(key, attribute)
branch, commit = utils.git_commit(bot.directory)
diff --git a/src/utils/decorators.py b/src/utils/decorators.py
index ca47ea6e..855d2b2e 100644
--- a/src/utils/decorators.py
+++ b/src/utils/decorators.py
@@ -37,12 +37,11 @@ def hook(event: str, **kwargs):
magic.add_hook(event, kwargs)
return func
return _hook_func
-def export(setting: str, value: typing.Any):
- def _export_func(module):
- magic = get_magic(module)
- magic.add_export(setting, value)
- return module
- return _export_func
+def export(setting: str, value: typing.Any=None):
+ def _export(obj: typing.Any):
+ get_magic(obj).add_export(setting, value)
+ return obj
+ return _export
def _kwarg(key: str, value: typing.Any, func: typing.Any):
magic = get_magic(func)