From 79fe7d8014d31e20f783820c2e859e8a6ac169cb Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Mon, 25 Aug 2003 20:19:42 +0000 Subject: [PATCH] Added thread, to make threaded commands in an unthreaded module. --- src/privmsgs.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/privmsgs.py b/src/privmsgs.py index 2abb56303..f64a02c49 100644 --- a/src/privmsgs.py +++ b/src/privmsgs.py @@ -33,6 +33,7 @@ from fix import * import gc import os +import new import sys import imp import linecache @@ -81,27 +82,8 @@ def getArgs(args, needed=1, optional=0): else: return ret -def getKeywordArgs(irc, msg, d=None): - if d is None: - d = {} - args = [] - tokenizer = callbacks.Tokenizer('=') - s = callbacks.addressed(irc.nick, msg) - tokens = tokenizer.tokenize(s) + [None, None] - counter = 0 - for (left, middle, right) in window(tokens, 3): - if counter: - counter -= 1 - continue - elif middle == '=': - d[callbacks.canonicalName(left)] = right - counter = 2 - else: - args.append(left) - del args[0] # The command name itself. - return (args, d) - def checkCapability(f, capability): + """Makes sure a user has a certain capability before a command will run.""" def newf(self, irc, msg, args): if ircdb.checkCapability(msg.prefix, capability): f(self, irc, msg, args) @@ -110,6 +92,15 @@ def checkCapability(f, capability): newf.__doc__ = f.__doc__ return newf +def thread(f): + """Makes sure a command spawns a thread when called.""" + def newf(self, irc, msg, args): + ff = new.instancemethod(f, self, self.__class__) + t = callbacks.CommandThread(ff, irc, msg, args) + t.start() + newf.__doc__ = f.__doc__ + return newf + class CapabilityCheckingPrivmsg(callbacks.Privmsg): capability = '' # To satisfy PyChecker def callCommand(self, f, irc, msg, args):