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
|
import fnmatch
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
@ -46,12 +43,12 @@ class cmd:
|
|||||||
self.aliases.append(self)
|
self.aliases.append(self)
|
||||||
alias = True
|
alias = True
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, func):
|
||||||
if self.func is None: # when function is defined; set self.func and call itself again
|
self.func = func
|
||||||
self.func = args[0]
|
self.__doc__ = self.func.__doc__
|
||||||
self.__doc__ = self.func.__doc__
|
return self
|
||||||
return self
|
|
||||||
|
|
||||||
|
def caller(self, *args):
|
||||||
largs = list(args)
|
largs = list(args)
|
||||||
|
|
||||||
cli, rawnick, chan, rest = largs
|
cli, rawnick, chan, rest = largs
|
||||||
@ -205,11 +202,12 @@ class hook:
|
|||||||
|
|
||||||
HOOKS[name].append(self)
|
HOOKS[name].append(self)
|
||||||
|
|
||||||
def __call__(self, *args):
|
def __call__(self, func):
|
||||||
if self.func is None:
|
self.func = func
|
||||||
self.func = args[0]
|
self.__doc__ = self.func.__doc__
|
||||||
self.__doc__ = self.func.__doc__
|
return self
|
||||||
return self
|
|
||||||
|
def caller(self, *args):
|
||||||
return self.func(*args)
|
return self.func(*args)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -59,7 +59,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
|
|
||||||
for fn in decorators.COMMANDS[""]:
|
for fn in decorators.COMMANDS[""]:
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, msg)
|
fn.caller(cli, rawnick, chan, msg)
|
||||||
except Exception:
|
except Exception:
|
||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise
|
raise
|
||||||
@ -79,7 +79,7 @@ def on_privmsg(cli, rawnick, chan, msg, notice = False):
|
|||||||
if not h or h[0] == " ":
|
if not h or h[0] == " ":
|
||||||
for fn in decorators.COMMANDS.get(x, []):
|
for fn in decorators.COMMANDS.get(x, []):
|
||||||
try:
|
try:
|
||||||
fn(cli, rawnick, chan, h.lstrip())
|
fn.caller(cli, rawnick, chan, h.lstrip())
|
||||||
except Exception:
|
except Exception:
|
||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise
|
raise
|
||||||
@ -94,7 +94,7 @@ def unhandled(cli, prefix, cmd, *args):
|
|||||||
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
if isinstance(arg, bytes): largs[i] = arg.decode('ascii')
|
||||||
for fn in decorators.HOOKS.get(cmd, []):
|
for fn in decorators.HOOKS.get(cmd, []):
|
||||||
try:
|
try:
|
||||||
fn(cli, prefix, *largs)
|
fn.caller(cli, prefix, *largs)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if botconfig.DEBUG_MODE:
|
if botconfig.DEBUG_MODE:
|
||||||
raise e
|
raise e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user