Fixed some bugs introduced with the latest refactoring of callCommand, etc.

This commit is contained in:
Jeremy Fincher 2005-02-17 22:39:44 +00:00
parent cb886de87e
commit 156084c225
6 changed files with 27 additions and 18 deletions

View File

@ -100,9 +100,9 @@ def getConfigVar(irc, msg, args, state):
addConverter('configVar', getConfigVar) addConverter('configVar', getConfigVar)
class Config(callbacks.Plugin): class Config(callbacks.Plugin):
def callCommand(self, method, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
super(Config, self).callCommand(method, irc, msg, *args, **kwargs) super(Config, self).callCommand(command, irc, msg, *args, **kwargs)
except registry.InvalidRegistryValue, e: except registry.InvalidRegistryValue, e:
irc.error(str(e)) irc.error(str(e))

View File

@ -47,7 +47,7 @@ class Ctcp(callbacks.PluginRegexp):
self.ignores = ircutils.IrcDict() self.ignores = ircutils.IrcDict()
self.floods = ircutils.FloodQueue(60) self.floods = ircutils.FloodQueue(60)
def callCommand(self, method, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
if conf.supybot.abuse.flood.ctcp(): if conf.supybot.abuse.flood.ctcp():
now = time.time() now = time.time()
for (ignore, expiration) in self.ignores.items(): for (ignore, expiration) in self.ignores.items():
@ -65,7 +65,7 @@ class Ctcp(callbacks.PluginRegexp):
ignoreMask = '*!%s@%s' % (msg.user, msg.host) ignoreMask = '*!%s@%s' % (msg.user, msg.host)
self.ignores[ignoreMask] = now + expires self.ignores[ignoreMask] = now + expires
return return
self.__parent.callCommand(method, irc, msg, *args, **kwargs) self.__parent.callCommand(command, irc, msg, *args, **kwargs)
def _reply(self, irc, msg, s): def _reply(self, irc, msg, s):
s = '\x01%s\x01' % s s = '\x01%s\x01' % s

View File

@ -108,9 +108,9 @@ class Google(callbacks.PluginRegexp):
self.__parent.__init__(irc) self.__parent.__init__(irc)
google.setLicense(self.registryValue('licenseKey')) google.setLicense(self.registryValue('licenseKey'))
def callCommand(self, method, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
self.__parent.callCommand(method, irc, msg, *args, **kwargs) self.__parent.callCommand(command, irc, msg, *args, **kwargs)
except xml.sax.SAXReaderNotAvailable, e: except xml.sax.SAXReaderNotAvailable, e:
irc.error('No XML parser available.') irc.error('No XML parser available.')

View File

@ -76,9 +76,9 @@ class ShrinkUrl(callbacks.PluginRegexp):
def die(self): def die(self):
self.db.close() self.db.close()
def callCommand(self, method, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
self.__parent.callCommand(method, irc, msg, *args, **kwargs) self.__parent.callCommand(command, irc, msg, *args, **kwargs)
except utils.web.Error, e: except utils.web.Error, e:
irc.error(str(e)) irc.error(str(e))

View File

@ -884,12 +884,12 @@ class CommandThread(world.SupyThread):
""" """
def __init__(self, target=None, args=(), kwargs={}): def __init__(self, target=None, args=(), kwargs={}):
self.command = args[0] self.command = args[0]
self.__parent = super(CommandThread, self) self.cb = target.im_self
self.method = self.cb.getCommandMethod(self.command)
threadName = 'Thread #%s (for %s.%s)' % (world.threadsSpawned, threadName = 'Thread #%s (for %s.%s)' % (world.threadsSpawned,
target.im_self.name(), self.cb.name(),
self.command) self.command)
log.debug('Spawning thread %s' % threadName) log.debug('Spawning thread %s (args: %r)', threadName, args)
self.__parent = super(CommandThread, self)
self.__parent.__init__(target=target, name=threadName, self.__parent.__init__(target=target, name=threadName,
args=args, kwargs=kwargs) args=args, kwargs=kwargs)
self.setDaemon(True) self.setDaemon(True)
@ -1016,15 +1016,24 @@ class Commands(object):
commands.sort() commands.sort()
return commands return commands
def callCommand(self, method, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
method = self.getCommandMethod(command)
method(irc, msg, *args, **kwargs) method(irc, msg, *args, **kwargs)
def _callCommand(self, command, irc, msg, *args, **kwargs): def _callCommand(self, command, irc, msg, *args, **kwargs):
method = self.getCommandMethod(command) if command is None:
assert self.callingCommand, \
'Received command=None without self.callingCommand.'
command = self.callingCommand
self.log.info('%s called by %s.', command, msg.prefix) self.log.info('%s called by %s.', command, msg.prefix)
try: try:
self.callCommand(method, irc, msg, *args, **kwargs) try:
self.callingCommand = command
self.callCommand(command, irc, msg, *args, **kwargs)
finally:
self.callingCommand = None
except (getopt.GetoptError, ArgumentError): except (getopt.GetoptError, ArgumentError):
method = self.getCommandMethod(command)
irc.reply(formatArgumentError(method, name=command)) irc.reply(formatArgumentError(method, name=command))
except (SyntaxError, Error), e: except (SyntaxError, Error), e:
self.log.debug('Error return: %s', utils.exnToString(e)) self.log.debug('Error return: %s', utils.exnToString(e))

View File

@ -59,9 +59,9 @@ 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, *L, **kwargs): def newf(self, irc, msg, args, *L, **kwargs):
if world.isMainThread(): if world.isMainThread():
t = callbacks.CommandThread(target=irc._callCommand, targetArgs = (self.callingCommand, irc, msg, args) + tuple(L)
args=(f.func_name, self), t = callbacks.CommandThread(target=self._callCommand,
kwargs=kwargs) args=targetArgs, kwargs=kwargs)
t.start() t.start()
else: else:
f(self, irc, msg, args, *L, **kwargs) f(self, irc, msg, args, *L, **kwargs)