From: John Runyon Date: Wed, 1 Nov 2023 20:54:52 +0000 (-0600) Subject: modlib - reorder hook functions and code to be consistent X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/438f73269cb57dc8002ff9234672da6b240ee5de modlib - reorder hook functions and code to be consistent --- diff --git a/modlib.py b/modlib.py index b09272e..ddb201a 100644 --- 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)