mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-02 17:29:22 +01:00
Made privmsgs wrappers stackable.
This commit is contained in:
parent
fad77c9545
commit
411289e625
@ -436,7 +436,7 @@ class CommandThread(threading.Thread):
|
||||
"""Just does some extra logging and error-recovery for commands that need
|
||||
to run in threads.
|
||||
"""
|
||||
def __init__(self, callCommand, command, irc, msg, args):
|
||||
def __init__(self, callCommand, command, irc, msg, args, *L):
|
||||
self.command = command
|
||||
world.threadsSpawned += 1
|
||||
try:
|
||||
@ -449,7 +449,7 @@ class CommandThread(threading.Thread):
|
||||
self.className = '<unknown>'
|
||||
name = '%s.%s with args %r' % (self.className, self.commandName, args)
|
||||
threading.Thread.__init__(self, target=callCommand, name=name,
|
||||
args=(command, irc, msg, args))
|
||||
args=(command, irc, msg, args)+L)
|
||||
debug.msg('Spawning thread %s' % name, 'verbose')
|
||||
self.irc = irc
|
||||
self.msg = msg
|
||||
@ -548,17 +548,17 @@ class Privmsg(irclib.IrcCallback):
|
||||
method = getattr(self, methodName)
|
||||
if inspect.ismethod(method):
|
||||
code = method.im_func.func_code
|
||||
return inspect.getargs(code) == (self.commandArgs, None, None)
|
||||
return inspect.getargs(code)[0] == self.commandArgs
|
||||
else:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
|
||||
def callCommand(self, f, irc, msg, args):
|
||||
def callCommand(self, f, irc, msg, args, *L):
|
||||
# Exceptions aren't caught here because IrcObjectProxy.finalEval
|
||||
# catches them and does The Right Thing.
|
||||
start = time.time()
|
||||
f(irc, msg, args)
|
||||
f(irc, msg, args, *L)
|
||||
elapsed = time.time() - start
|
||||
funcname = f.im_func.func_name
|
||||
debug.msg('%s.%s took %s seconds' % \
|
||||
|
@ -88,12 +88,13 @@ def checkCapability(f, capability):
|
||||
|
||||
def checkChannelCapability(f, capability):
|
||||
"""Makes sure a user has a certain channel capability before running f."""
|
||||
def newf(self, irc, msg, args):
|
||||
def newf(self, irc, msg, args, *L):
|
||||
channel = getChannel(msg, args) # Make a copy, f might getChannel.
|
||||
chancap = ircdb.makeChannelCapability(channel, capability)
|
||||
if ircdb.checkCapability(msg.prefix, chancap):
|
||||
L += (channel,)
|
||||
ff = new.instancemethod(f, self, self.__class__)
|
||||
ff(irc, msg, args, channel)
|
||||
ff(irc, msg, args, *L)
|
||||
else:
|
||||
irc.error(msg, conf.replyNoCapability % chancap)
|
||||
newf.__doc__ = f.__doc__
|
||||
@ -101,16 +102,16 @@ def checkChannelCapability(f, capability):
|
||||
|
||||
def thread(f):
|
||||
"""Makes sure a command spawns a thread when called."""
|
||||
def newf(self, irc, msg, args):
|
||||
def newf(self, irc, msg, args, *L):
|
||||
ff = new.instancemethod(f, self, self.__class__)
|
||||
t = callbacks.CommandThread(self.callCommand, ff, irc, msg, args)
|
||||
t = callbacks.CommandThread(self.callCommand, ff, irc, msg, args, *L)
|
||||
t.start()
|
||||
newf.__doc__ = f.__doc__
|
||||
return newf
|
||||
|
||||
def name(f):
|
||||
"""Makes sure a name is available based on conf.requireRegistration."""
|
||||
def newf(self, irc, msg, args):
|
||||
def newf(self, irc, msg, args, *L):
|
||||
try:
|
||||
name = ircdb.users.getUser(msg.prefix).name
|
||||
except KeyError:
|
||||
@ -119,17 +120,19 @@ def name(f):
|
||||
return
|
||||
else:
|
||||
name = msg.prefix
|
||||
L = (name,) + L
|
||||
ff = new.instancemethod(f, self, self.__class__)
|
||||
ff(irc, msg, args, name)
|
||||
ff(irc, msg, args, *L)
|
||||
newf.__doc__ = f.__doc__
|
||||
return newf
|
||||
|
||||
def channel(f):
|
||||
"""Gives the command an extra channel arg as if it had called getChannel"""
|
||||
def newf(self, irc, msg, args):
|
||||
def newf(self, irc, msg, args, *L):
|
||||
channel = getChannel(msg, args)
|
||||
L = (channel,) + L
|
||||
ff = new.instancemethod(f, self, self.__class__)
|
||||
ff(irc, msg, args, channel)
|
||||
ff(irc, msg, args, *L)
|
||||
newf.__doc__ = f.__doc__
|
||||
return newf
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user