]> jfr.im git - erebus.git/commitdiff
modlib - reorder hook functions and code to be consistent
authorJohn Runyon <redacted>
Wed, 1 Nov 2023 20:54:52 +0000 (14:54 -0600)
committerJohn Runyon <redacted>
Wed, 1 Nov 2023 20:54:52 +0000 (14:54 -0600)
modlib.py

index b09272e89b3704d8daa3ef3f7d03b0555db3e05e..ddb201a252b9cc70e02ccc0d335f6eb105b2fc83 100644 (file)
--- a/modlib.py
+++ b/modlib.py
@@ -60,9 +60,9 @@ class modlib(object):
 
        def __init__(self, name):
                self.hooks = {}
-               self.numhooks = {}
                self.chanhooks = {}
                self.exceptionhooks = []
+               self.numhooks = {}
                self.helps = []
                self.parent = None
 
@@ -80,12 +80,12 @@ class modlib(object):
                for cmd, func in self.hooks.items():
                        parent.hook(cmd, func)
                        parent.hook("%s.%s" % (self.name, cmd), func)
-               for num, func in self.numhooks.items():
-                       parent.hooknum(num, func)
                for chan, func in self.chanhooks.items():
                        parent.hookchan(chan, func)
                for exc, func in self.exceptionhooks:
                        parent.hookexception(exc, func)
+               for num, func in self.numhooks.items():
+                       parent.hooknum(num, func)
 
                for func, args, kwargs in self.helps:
                        try:
@@ -97,12 +97,12 @@ class modlib(object):
                for cmd, func in self.hooks.items():
                        parent.unhook(cmd, func)
                        parent.unhook("%s.%s" % (self.name, cmd), func)
-               for num, func in self.numhooks.items():
-                       parent.unhooknum(num, func)
                for chan, func in self.chanhooks.items():
                        parent.unhookchan(chan, func)
                for exc, func in self.exceptionhooks:
                        parent.unhookexception(exc, func)
+               for num, func in self.numhooks.items():
+                       parent.unhooknum(num, func)
 
                for func, args, kwargs in self.helps:
                        try:
@@ -111,30 +111,6 @@ class modlib(object):
                                pass
                return True
 
-       def hookexception(self, exc):
-               def realhook(func):
-                       self.exceptionhooks.append((exc, func))
-                       if self.parent is not None:
-                               self.parent.hookexception(exc, func)
-                       return func
-               return realhook
-
-       def hooknum(self, num):
-               def realhook(func):
-                       self.numhooks[str(num)] = func
-                       if self.parent is not None:
-                               self.parent.hooknum(str(num), func)
-                       return func
-               return realhook
-
-       def hookchan(self, chan, glevel=ANYONE, clevel=PUBLIC):
-               def realhook(func):
-                       self.chanhooks[chan] = func
-                       if self.parent is not None:
-                               self.parent.hookchan(chan, func)
-                       return func
-               return realhook
-
        def hook(self, cmd=None, needchan=True, glevel=ANYONE, clevel=PUBLIC, wantchan=None):
                if wantchan is None: wantchan = needchan
                _cmd = cmd #save this since it gets wiped out...
@@ -163,6 +139,30 @@ class modlib(object):
                        return func
                return realhook
 
+       def hookchan(self, chan, glevel=ANYONE, clevel=PUBLIC):
+               def realhook(func):
+                       self.chanhooks[chan] = func
+                       if self.parent is not None:
+                               self.parent.hookchan(chan, func)
+                       return func
+               return realhook
+
+       def hookexception(self, exc):
+               def realhook(func):
+                       self.exceptionhooks.append((exc, func))
+                       if self.parent is not None:
+                               self.parent.hookexception(exc, func)
+                       return func
+               return realhook
+
+       def hooknum(self, num):
+               def realhook(func):
+                       self.numhooks[str(num)] = func
+                       if self.parent is not None:
+                               self.parent.hooknum(str(num), func)
+                       return func
+               return realhook
+
        def mod(self, modname):
                if self.parent is not None:
                        return self.parent.module(modname)