mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Moved ambiguous command handling to Owner; fixed handling of empty nested command.
This commit is contained in:
parent
0011fff94e
commit
e556e783b1
@ -53,7 +53,8 @@ class Misc(callbacks.Privmsg):
|
||||
priority = sys.maxint
|
||||
def invalidCommand(self, irc, msg, tokens):
|
||||
if conf.replyWhenNotCommand:
|
||||
irc.error(msg, '%r is not a valid command.' % tokens[0])
|
||||
command = tokens and tokens[0] or ''
|
||||
irc.error(msg, '%r is not a valid command.' % command)
|
||||
else:
|
||||
if not isinstance(irc.irc, irclib.Irc):
|
||||
irc.reply(msg, '[%s]' % ' '.join(tokens))
|
||||
|
32
src/Owner.py
32
src/Owner.py
@ -88,11 +88,37 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
||||
|
||||
def doPrivmsg(self, irc, msg):
|
||||
callbacks.Privmsg.handled = False
|
||||
notCommands = []
|
||||
ambiguousCommands = {}
|
||||
s = callbacks.addressed(irc.nick, msg)
|
||||
if s:
|
||||
callbacks.IrcObjectProxy(irc, msg, callbacks.tokenize(s))
|
||||
tokens = callbacks.tokenize(s)
|
||||
ambiguousCommands = {}
|
||||
commands = callbacks.getCommands(tokens)
|
||||
for command in commands:
|
||||
command = callbacks.canonicalName(command)
|
||||
cbs = callbacks.findCallbackForCommand(irc, command)
|
||||
if len(cbs) > 1:
|
||||
ambiguousCommands[command] = [cb.name() for cb in cbs]
|
||||
if ambiguousCommands:
|
||||
if len(ambiguousCommands) == 1: # Common case.
|
||||
(command, names) = ambiguousCommands.popitem()
|
||||
names.sort()
|
||||
s = 'The command %r is available in the %s plugins. '\
|
||||
'Please specify the plugin whose command you ' \
|
||||
'wish to call by using its name as a command ' \
|
||||
'before calling it.' % \
|
||||
(command, utils.commaAndify(names))
|
||||
else:
|
||||
L = []
|
||||
for (command, names) in ambiguousCommands.iteritems():
|
||||
names.sort()
|
||||
L.append('The command %r is available in the %s '
|
||||
'plugins' %
|
||||
(command, utils.commaAndify(names)))
|
||||
s = '%s; please specify from which plugins to ' \
|
||||
'call these commands.' % '; '.join(L)
|
||||
irc.queueMsg(callbacks.error(msg, s))
|
||||
else:
|
||||
callbacks.IrcObjectProxy(irc, msg, tokens)
|
||||
|
||||
def eval(self, irc, msg, args):
|
||||
"""<expression>
|
||||
|
@ -341,38 +341,6 @@ class IrcObjectProxy:
|
||||
"A proxy object to allow proper nested of commands (even threaded ones)."
|
||||
def __init__(self, irc, msg, args):
|
||||
#debug.printf('__init__: %s' % args)
|
||||
if not args:
|
||||
irc.reply(msg, '[]')
|
||||
else:
|
||||
if isinstance(irc, irclib.Irc):
|
||||
# Let's check for {ambiguous,non}Commands.
|
||||
ambiguousCommands = {}
|
||||
commands = getCommands(args)
|
||||
for command in commands:
|
||||
command = canonicalName(command)
|
||||
cbs = findCallbackForCommand(irc, command)
|
||||
if len(cbs) > 1:
|
||||
ambiguousCommands[command] = [cb.name() for cb in cbs]
|
||||
if ambiguousCommands:
|
||||
if len(ambiguousCommands) == 1: # Common case.
|
||||
(command, names) = ambiguousCommands.popitem()
|
||||
names.sort()
|
||||
s = 'The command %r is available in the %s plugins. '\
|
||||
'Please specify the plugin whose command you ' \
|
||||
'wish to call by using its name as a command ' \
|
||||
'before calling it.' % \
|
||||
(command, utils.commaAndify(names))
|
||||
else:
|
||||
L = []
|
||||
for (command, names) in ambiguousCommands.iteritems():
|
||||
names.sort()
|
||||
L.append('The command %r is available in the %s '
|
||||
'plugins' %
|
||||
(command, utils.commaAndify(names)))
|
||||
s = '%s; please specify from which plugins to ' \
|
||||
'call these commands.' % '; '.join(L)
|
||||
irc.queueMsg(error(msg, s))
|
||||
return
|
||||
self.irc = irc
|
||||
self.msg = msg
|
||||
self.args = args
|
||||
@ -382,8 +350,12 @@ class IrcObjectProxy:
|
||||
self.private = False
|
||||
self.finished = False
|
||||
self.prefixName = True
|
||||
self.finalEvaled = False
|
||||
self.noLengthCheck = False
|
||||
if not args:
|
||||
self.finalEvaled = True
|
||||
self._callInvalidCommands()
|
||||
else:
|
||||
self.finalEvaled = False
|
||||
world.commandsProcessed += 1
|
||||
self.evalArgs()
|
||||
|
||||
@ -396,6 +368,13 @@ class IrcObjectProxy:
|
||||
return
|
||||
self.finalEval()
|
||||
|
||||
def _callInvalidCommands(self):
|
||||
for cb in self.irc.callbacks:
|
||||
if self.finished:
|
||||
break
|
||||
if hasattr(cb, 'invalidCommand'):
|
||||
cb.invalidCommand(self, self.msg, self.args)
|
||||
|
||||
def finalEval(self):
|
||||
assert not self.finalEvaled, 'finalEval called twice.'
|
||||
self.finalEvaled = True
|
||||
@ -417,11 +396,7 @@ class IrcObjectProxy:
|
||||
if r.search(self.msg.args[1]):
|
||||
return
|
||||
# Ok, no regexp-based things matched.
|
||||
for cb in self.irc.callbacks:
|
||||
if self.finished:
|
||||
break
|
||||
if hasattr(cb, 'invalidCommand'):
|
||||
cb.invalidCommand(self, self.msg, self.args)
|
||||
self._callInvalidCommands()
|
||||
else:
|
||||
try:
|
||||
assert len(cbs) == 1
|
||||
|
Loading…
Reference in New Issue
Block a user