]> jfr.im git - erebus.git/commitdiff
Added hooknum in modlib
authorzonidjan <redacted>
Fri, 24 Jan 2014 08:36:02 +0000 (02:36 -0600)
committerzonidjan <redacted>
Fri, 24 Jan 2014 08:36:02 +0000 (02:36 -0600)
modlib.py

index 696288104f4aecb3b476ad34e942fd2cc2e552e7..4c349c0f6c55f9e30657af3c89ecdb18ccfcc8b6 100644 (file)
--- a/modlib.py
+++ b/modlib.py
@@ -33,6 +33,7 @@ class modlib(object):
 
        def __init__(self, name):
                self.hooks = {}
+               self.numhooks = {}
                self.parent = None
 
                self.name = name
@@ -41,12 +42,24 @@ class modlib(object):
                self.parent = parent
                for cmd, func in self.hooks.iteritems():
                        self.parent.hook(cmd, func)
+               for num, func in self.numhooks.iteritems():
+                       self.parent.hooknum(num, func)
                return True
        def modstop(self, parent):
                for cmd, func in self.hooks.iteritems():
                        self.parent.unhook(cmd, func)
+               for num, func in self.numhooks.iteritems():
+                       self.parent.unhooknum(num, func)
                return True
 
+       def hooknum(self, num):
+               def realhook(func):
+                       self.numhooks[num] = func
+                       if self.parent is not None:
+                               self.parent.hooknum(num, func)
+                       return func
+               return realhook
+
        def hook(self, cmd, needchan=True, glevel=ANYONE, clevel=PUBLIC):
                def realhook(func):
                        func.needchan = needchan