From 411289e625c9b997a4c5efaf485924bb27ef2eac Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 17 Sep 2003 23:31:45 +0000 Subject: [PATCH] Made privmsgs wrappers stackable. --- src/callbacks.py | 10 +++++----- src/privmsgs.py | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/callbacks.py b/src/callbacks.py index 29a241d0b..05eedfd82 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -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 = '' 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' % \ diff --git a/src/privmsgs.py b/src/privmsgs.py index cd83c4070..c27ebdbb5 100644 --- a/src/privmsgs.py +++ b/src/privmsgs.py @@ -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