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