From: zonidjan Date: Sat, 23 Nov 2013 18:46:17 +0000 (-0600) Subject: Starting module API X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/6c70d82c5f62387494753a5080b21e1c8ab1f98c Starting module API --- diff --git a/modlib.py b/modlib.py new file mode 100644 index 0000000..eb9923f --- /dev/null +++ b/modlib.py @@ -0,0 +1,19 @@ +class modlib(object): + hooks = {} + parent = None + + def __init__(self, name): + self.name = name + + def modstart(self, parent): + self.parent = parent + for cmd, func in self.hooks.iteritems(): + self.parent.hook(cmd, func) + + def hook(self, cmd): + def realhook(func): + self.hooks[cmd] = func + if self.parent is not None: + self.parent.hook(cmd, func) + return func + return realhook diff --git a/modules/modtest.py b/modules/modtest.py new file mode 100644 index 0000000..ea2f4d9 --- /dev/null +++ b/modules/modtest.py @@ -0,0 +1,9 @@ +# preamble +import modlib +lib = modlib.modlib(__name__) +modstart = lib.modstart + +#module code +@lib.hook('test') +def cmd_test(bot, user, chan, *args): + bot.msg(chan, "You said: !test %s" % (' '.join([str(arg) for arg in args])))