Added thread, to make threaded commands in an unthreaded module.

This commit is contained in:
Jeremy Fincher 2003-08-25 20:19:42 +00:00
parent edebbe448c
commit 79fe7d8014
1 changed files with 11 additions and 20 deletions

View File

@ -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):