diff --git a/importer.py b/importer.py index f4c011f..810daa1 100644 --- a/importer.py +++ b/importer.py @@ -151,6 +151,7 @@ class ModuleLoader(SourceLoader): module.print = lambda msg: print("[%s] %s"%(module.name, msg)) module.print_debug = lambda msg: mod_print_dbg(module, msg) module.send_response = lambda srv, res: mod_send_response(self.context, srv, res) + module.add_hook = lambda store, hook: self.context.hooks.add_hook(store, hook, module) if not hasattr(module, "NODATA"): module.DATAS = xmlparser.parse_file(self.context.datas_path diff --git a/modules/alias/__init__.py b/modules/alias/__init__.py index a4cb582..e671b06 100644 --- a/modules/alias/__init__.py +++ b/modules/alias/__init__.py @@ -14,8 +14,8 @@ def load(context): CONTEXT = context from hooks import Hook - context.hooks.add_hook("cmd_hook", Hook(cmd_set, "set")) - context.hooks.add_hook("all_pre", Hook(treat_variables)) + add_hook("cmd_hook", Hook(cmd_set, "set")) + add_hook("all_pre", Hook(treat_variables)) global DATAS if not DATAS.hasNode("aliases"): diff --git a/modules/ddg/__init__.py b/modules/ddg/__init__.py index fa265c2..ad00b4c 100644 --- a/modules/ddg/__init__.py +++ b/modules/ddg/__init__.py @@ -13,23 +13,23 @@ def load(context): WFASearch.CONF = CONF from hooks import Hook - context.hooks.add_hook("cmd_hook", Hook(define, "d")) - context.hooks.add_hook("cmd_hook", Hook(define, "def")) - context.hooks.add_hook("cmd_hook", Hook(define, "defini")) - context.hooks.add_hook("cmd_hook", Hook(define, "definit")) - context.hooks.add_hook("cmd_hook", Hook(define, "define")) - context.hooks.add_hook("cmd_hook", Hook(define, "definition")) - context.hooks.add_hook("cmd_hook", Hook(search, "search")) - context.hooks.add_hook("cmd_hook", Hook(search, "ddg")) - context.hooks.add_hook("cmd_hook", Hook(search, "g")) - context.hooks.add_hook("cmd_hook", Hook(calculate, "wa")) - context.hooks.add_hook("cmd_hook", Hook(calculate, "wfa")) - context.hooks.add_hook("cmd_hook", Hook(calculate, "calc")) - context.hooks.add_hook("cmd_hook", Hook(wiki, "w")) - context.hooks.add_hook("cmd_hook", Hook(wiki, "wf")) - context.hooks.add_hook("cmd_hook", Hook(wiki, "wfr")) - context.hooks.add_hook("cmd_hook", Hook(wiki, "we")) - context.hooks.add_hook("cmd_hook", Hook(wiki, "wen")) + add_hook("cmd_hook", Hook(define, "d")) + add_hook("cmd_hook", Hook(define, "def")) + add_hook("cmd_hook", Hook(define, "defini")) + add_hook("cmd_hook", Hook(define, "definit")) + add_hook("cmd_hook", Hook(define, "define")) + add_hook("cmd_hook", Hook(define, "definition")) + add_hook("cmd_hook", Hook(search, "search")) + add_hook("cmd_hook", Hook(search, "ddg")) + add_hook("cmd_hook", Hook(search, "g")) + add_hook("cmd_hook", Hook(calculate, "wa")) + add_hook("cmd_hook", Hook(calculate, "wfa")) + add_hook("cmd_hook", Hook(calculate, "calc")) + add_hook("cmd_hook", Hook(wiki, "w")) + add_hook("cmd_hook", Hook(wiki, "wf")) + add_hook("cmd_hook", Hook(wiki, "wfr")) + add_hook("cmd_hook", Hook(wiki, "we")) + add_hook("cmd_hook", Hook(wiki, "wen")) def reload(): imp.reload(DDGSearch) diff --git a/modules/sleepytime.py b/modules/sleepytime.py index 95941ff..8482b99 100644 --- a/modules/sleepytime.py +++ b/modules/sleepytime.py @@ -16,8 +16,8 @@ def help_full (): def load(context): from hooks import Hook - context.hooks.add_hook("cmd_hook", Hook(cmd_sleep, "sleeptime")) - context.hooks.add_hook("cmd_hook", Hook(cmd_sleep, "sleepytime")) + add_hook("cmd_hook", Hook(cmd_sleep, "sleeptime")) + add_hook("cmd_hook", Hook(cmd_sleep, "sleepytime")) def cmd_sleep(msg): diff --git a/modules/syno.py b/modules/syno.py index fc61f01..7a40f4e 100644 --- a/modules/syno.py +++ b/modules/syno.py @@ -15,8 +15,8 @@ def help_full (): def load(context): from hooks import Hook - context.hooks.add_hook("cmd_hook", Hook(cmd_syno, "syno")) - context.hooks.add_hook("cmd_hook", Hook(cmd_syno, "synonyme")) + add_hook("cmd_hook", Hook(cmd_syno, "syno")) + add_hook("cmd_hook", Hook(cmd_syno, "synonyme")) def cmd_syno(msg): diff --git a/modules/translate.py b/modules/translate.py index 5f87262..e911150 100644 --- a/modules/translate.py +++ b/modules/translate.py @@ -15,10 +15,10 @@ LANG = ["ar", "zh", "cz", "en", "fr", "gr", "it", def load(context): from hooks import Hook - context.hooks.add_hook("cmd_hook", Hook(cmd_translate, "translate")) - context.hooks.add_hook("cmd_hook", Hook(cmd_translate, "traduction")) - context.hooks.add_hook("cmd_hook", Hook(cmd_translate, "traduit")) - context.hooks.add_hook("cmd_hook", Hook(cmd_translate, "traduire")) + add_hook("cmd_hook", Hook(cmd_translate, "translate")) + add_hook("cmd_hook", Hook(cmd_translate, "traduction")) + add_hook("cmd_hook", Hook(cmd_translate, "traduit")) + add_hook("cmd_hook", Hook(cmd_translate, "traduire")) def cmd_translate(msg):