mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 22:51:01 +01:00
Fixed 'useless reply on bad arguments' in threaded commands; added/changed Combine class.
This commit is contained in:
parent
e4591e3d57
commit
e4fd36ffef
@ -299,6 +299,7 @@ class IrcObjectProxy:
|
|||||||
|
|
||||||
class CommandThread(threading.Thread):
|
class CommandThread(threading.Thread):
|
||||||
def __init__(self, command, irc, msg, args):
|
def __init__(self, command, irc, msg, args):
|
||||||
|
self.command = command
|
||||||
self.commandName = command.im_func.func_name
|
self.commandName = command.im_func.func_name
|
||||||
self.className = command.im_class.__name__
|
self.className = command.im_class.__name__
|
||||||
name = '%s.%s with args %r' % (self.className, self.commandName, args)
|
name = '%s.%s with args %r' % (self.className, self.commandName, args)
|
||||||
@ -316,7 +317,7 @@ class CommandThread(threading.Thread):
|
|||||||
debug.msg('%s took %s seconds.' % \
|
debug.msg('%s took %s seconds.' % \
|
||||||
(self.commandName, elapsed), 'verbose')
|
(self.commandName, elapsed), 'verbose')
|
||||||
except ArgumentError:
|
except ArgumentError:
|
||||||
self.reply(self.msg, command.__doc__.splitlines()[0])
|
self.irc.reply(self.msg, self.command.__doc__.splitlines()[0])
|
||||||
except Error, e:
|
except Error, e:
|
||||||
self.irc.reply(self.msg, debug.exnToString(e))
|
self.irc.reply(self.msg, debug.exnToString(e))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
@ -456,12 +457,15 @@ class PrivmsgRegexp(Privmsg):
|
|||||||
|
|
||||||
|
|
||||||
class Combine:
|
class Combine:
|
||||||
|
classes = [] # Override in a subclass.
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
for cls in self.classes:
|
for instance in self.instances:
|
||||||
if hasattr(cls, attr):
|
try:
|
||||||
return getattr(cls, attr)
|
return getattr(instance, attr)
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
raise AttributeError, attr
|
raise AttributeError, attr
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self.instances = []
|
self.instances = []
|
||||||
for cls in self.classes:
|
for cls in self.classes:
|
||||||
@ -479,17 +483,30 @@ class Combine:
|
|||||||
def outFilter(self, irc, msg):
|
def outFilter(self, irc, msg):
|
||||||
for instance in self.instances:
|
for instance in self.instances:
|
||||||
msg = instance.outFilter(irc, msg)
|
msg = instance.outFilter(irc, msg)
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def isCommand(self, *args, **kwargs):
|
||||||
|
for instance in self.instances:
|
||||||
|
if instance.isCommand(*args, **kwargs):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def callCommand(self, f, *args, **kwargs):
|
||||||
|
for instance in self.instances:
|
||||||
|
if instance.__class__ == f.im_class:
|
||||||
|
return instance.callCommand(f, *args, **kwargs)
|
||||||
|
|
||||||
|
assert False
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return 'Combine(%s)' % \
|
return self.__class__.__name__
|
||||||
','.join([cls.__name__ for cls in self.classes])
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
for instance in instances:
|
for instance in self.instances:
|
||||||
instance.reset()
|
instance.reset()
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
for instance in instances:
|
for instance in self.instances:
|
||||||
instance.die()
|
instance.die()
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user