mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Fixed some bugs introduced with the latest refactoring of callCommand, etc.
This commit is contained in:
parent
cb886de87e
commit
156084c225
@ -100,9 +100,9 @@ def getConfigVar(irc, msg, args, state):
|
||||
addConverter('configVar', getConfigVar)
|
||||
|
||||
class Config(callbacks.Plugin):
|
||||
def callCommand(self, method, irc, msg, *args, **kwargs):
|
||||
def callCommand(self, command, irc, msg, *args, **kwargs):
|
||||
try:
|
||||
super(Config, self).callCommand(method, irc, msg, *args, **kwargs)
|
||||
super(Config, self).callCommand(command, irc, msg, *args, **kwargs)
|
||||
except registry.InvalidRegistryValue, e:
|
||||
irc.error(str(e))
|
||||
|
||||
|
@ -47,7 +47,7 @@ class Ctcp(callbacks.PluginRegexp):
|
||||
self.ignores = ircutils.IrcDict()
|
||||
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():
|
||||
now = time.time()
|
||||
for (ignore, expiration) in self.ignores.items():
|
||||
@ -65,7 +65,7 @@ class Ctcp(callbacks.PluginRegexp):
|
||||
ignoreMask = '*!%s@%s' % (msg.user, msg.host)
|
||||
self.ignores[ignoreMask] = now + expires
|
||||
return
|
||||
self.__parent.callCommand(method, irc, msg, *args, **kwargs)
|
||||
self.__parent.callCommand(command, irc, msg, *args, **kwargs)
|
||||
|
||||
def _reply(self, irc, msg, s):
|
||||
s = '\x01%s\x01' % s
|
||||
|
@ -108,9 +108,9 @@ class Google(callbacks.PluginRegexp):
|
||||
self.__parent.__init__(irc)
|
||||
google.setLicense(self.registryValue('licenseKey'))
|
||||
|
||||
def callCommand(self, method, irc, msg, *args, **kwargs):
|
||||
def callCommand(self, command, irc, msg, *args, **kwargs):
|
||||
try:
|
||||
self.__parent.callCommand(method, irc, msg, *args, **kwargs)
|
||||
self.__parent.callCommand(command, irc, msg, *args, **kwargs)
|
||||
except xml.sax.SAXReaderNotAvailable, e:
|
||||
irc.error('No XML parser available.')
|
||||
|
||||
|
@ -76,9 +76,9 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
||||
def die(self):
|
||||
self.db.close()
|
||||
|
||||
def callCommand(self, method, irc, msg, *args, **kwargs):
|
||||
def callCommand(self, command, irc, msg, *args, **kwargs):
|
||||
try:
|
||||
self.__parent.callCommand(method, irc, msg, *args, **kwargs)
|
||||
self.__parent.callCommand(command, irc, msg, *args, **kwargs)
|
||||
except utils.web.Error, e:
|
||||
irc.error(str(e))
|
||||
|
||||
|
@ -884,12 +884,12 @@ class CommandThread(world.SupyThread):
|
||||
"""
|
||||
def __init__(self, target=None, args=(), kwargs={}):
|
||||
self.command = args[0]
|
||||
self.__parent = super(CommandThread, self)
|
||||
self.method = self.cb.getCommandMethod(self.command)
|
||||
self.cb = target.im_self
|
||||
threadName = 'Thread #%s (for %s.%s)' % (world.threadsSpawned,
|
||||
target.im_self.name(),
|
||||
self.cb.name(),
|
||||
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,
|
||||
args=args, kwargs=kwargs)
|
||||
self.setDaemon(True)
|
||||
@ -1016,15 +1016,24 @@ class Commands(object):
|
||||
commands.sort()
|
||||
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)
|
||||
|
||||
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)
|
||||
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):
|
||||
method = self.getCommandMethod(command)
|
||||
irc.reply(formatArgumentError(method, name=command))
|
||||
except (SyntaxError, Error), e:
|
||||
self.log.debug('Error return: %s', utils.exnToString(e))
|
||||
|
@ -59,9 +59,9 @@ def thread(f):
|
||||
"""Makes sure a command spawns a thread when called."""
|
||||
def newf(self, irc, msg, args, *L, **kwargs):
|
||||
if world.isMainThread():
|
||||
t = callbacks.CommandThread(target=irc._callCommand,
|
||||
args=(f.func_name, self),
|
||||
kwargs=kwargs)
|
||||
targetArgs = (self.callingCommand, irc, msg, args) + tuple(L)
|
||||
t = callbacks.CommandThread(target=self._callCommand,
|
||||
args=targetArgs, kwargs=kwargs)
|
||||
t.start()
|
||||
else:
|
||||
f(self, irc, msg, args, *L, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user