Tweak the decorators to no longer have mangled __call__
This commit is contained in:
parent
ca2e901d58
commit
f1285d2237
@ -1,6 +1,3 @@
|
||||
# Old, obsolete & original code by jcao219
|
||||
# rewritten by Vgr
|
||||
|
||||
import fnmatch
|
||||
from collections import defaultdict
|
||||
|
||||
@ -46,12 +43,12 @@ class cmd:
|
||||
self.aliases.append(self)
|
||||
alias = True
|
||||
|
||||
def __call__(self, *args):
|
||||
if self.func is None: # when function is defined; set self.func and call itself again
|
||||
self.func = args[0]
|
||||
def __call__(self, func):
|
||||
self.func = func
|
||||
self.__doc__ = self.func.__doc__
|
||||
return self
|
||||
|
||||
def caller(self, *args):
|
||||
largs = list(args)
|
||||
|
||||
cli, rawnick, chan, rest = largs
|
||||
@ -205,11 +202,12 @@ class hook:
|
||||
|
||||
HOOKS[name].append(self)
|
||||
|
||||
def __call__(self, *args):
|
||||
if self.func is None:
|
||||
self.func = args[0]
|
||||
def __call__(self, func):
|
||||
self.func = func
|
||||
self.__doc__ = self.func.__doc__
|
||||
return self
|
||||
|
||||
def caller(self, *args):
|
||||
return self.func(*args)
|
||||
|
||||
@staticmethod
|
||||
|
@ -59,7 +59,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||
|
||||
for fn in decorators.COMMANDS[""]:
|
||||
try:
|
||||
fn(cli, rawnick, chan, msg)
|
||||
fn.caller(cli, rawnick, chan, msg)
|
||||
except Exception:
|
||||
if botconfig.DEBUG_MODE:
|
||||
raise
|
||||
@ -79,7 +79,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
||||
if not h or h[0] == " ":
|
||||
for fn in decorators.COMMANDS.get(x, []):
|
||||
try:
|
||||
fn(cli, rawnick, chan, h.lstrip())
|
||||
fn.caller(cli, rawnick, chan, h.lstrip())
|
||||
except Exception:
|
||||
if botconfig.DEBUG_MODE:
|
||||
raise
|
||||
@ -94,7 +94,7 @@ def unhandled(cli, prefix, cmd, *args):
|
||||
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
||||
for fn in decorators.HOOKS.get(cmd, []):
|
||||
try:
|
||||
fn(cli, prefix, *largs)
|
||||
fn.caller(cli, prefix, *largs)
|
||||
except Exception as e:
|
||||
if botconfig.DEBUG_MODE:
|
||||
raise e
|
||||
|
Loading…
x
Reference in New Issue
Block a user