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
|
priority = sys.maxint
|
||||||
def invalidCommand(self, irc, msg, tokens):
|
def invalidCommand(self, irc, msg, tokens):
|
||||||
if conf.replyWhenNotCommand:
|
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:
|
else:
|
||||||
if not isinstance(irc.irc, irclib.Irc):
|
if not isinstance(irc.irc, irclib.Irc):
|
||||||
irc.reply(msg, '[%s]' % ' '.join(tokens))
|
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):
|
def doPrivmsg(self, irc, msg):
|
||||||
callbacks.Privmsg.handled = False
|
callbacks.Privmsg.handled = False
|
||||||
notCommands = []
|
|
||||||
ambiguousCommands = {}
|
|
||||||
s = callbacks.addressed(irc.nick, msg)
|
s = callbacks.addressed(irc.nick, msg)
|
||||||
if s:
|
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):
|
def eval(self, irc, msg, args):
|
||||||
"""<expression>
|
"""<expression>
|
||||||
|
@ -341,49 +341,21 @@ class IrcObjectProxy:
|
|||||||
"A proxy object to allow proper nested of commands (even threaded ones)."
|
"A proxy object to allow proper nested of commands (even threaded ones)."
|
||||||
def __init__(self, irc, msg, args):
|
def __init__(self, irc, msg, args):
|
||||||
#debug.printf('__init__: %s' % args)
|
#debug.printf('__init__: %s' % args)
|
||||||
|
self.irc = irc
|
||||||
|
self.msg = msg
|
||||||
|
self.args = args
|
||||||
|
self.counter = 0
|
||||||
|
self.action = False
|
||||||
|
self.notice = False
|
||||||
|
self.private = False
|
||||||
|
self.finished = False
|
||||||
|
self.prefixName = True
|
||||||
|
self.noLengthCheck = False
|
||||||
if not args:
|
if not args:
|
||||||
irc.reply(msg, '[]')
|
self.finalEvaled = True
|
||||||
|
self._callInvalidCommands()
|
||||||
else:
|
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
|
|
||||||
self.counter = 0
|
|
||||||
self.action = False
|
|
||||||
self.notice = False
|
|
||||||
self.private = False
|
|
||||||
self.finished = False
|
|
||||||
self.prefixName = True
|
|
||||||
self.finalEvaled = False
|
self.finalEvaled = False
|
||||||
self.noLengthCheck = False
|
|
||||||
world.commandsProcessed += 1
|
world.commandsProcessed += 1
|
||||||
self.evalArgs()
|
self.evalArgs()
|
||||||
|
|
||||||
@ -396,6 +368,13 @@ class IrcObjectProxy:
|
|||||||
return
|
return
|
||||||
self.finalEval()
|
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):
|
def finalEval(self):
|
||||||
assert not self.finalEvaled, 'finalEval called twice.'
|
assert not self.finalEvaled, 'finalEval called twice.'
|
||||||
self.finalEvaled = True
|
self.finalEvaled = True
|
||||||
@ -417,11 +396,7 @@ class IrcObjectProxy:
|
|||||||
if r.search(self.msg.args[1]):
|
if r.search(self.msg.args[1]):
|
||||||
return
|
return
|
||||||
# Ok, no regexp-based things matched.
|
# Ok, no regexp-based things matched.
|
||||||
for cb in self.irc.callbacks:
|
self._callInvalidCommands()
|
||||||
if self.finished:
|
|
||||||
break
|
|
||||||
if hasattr(cb, 'invalidCommand'):
|
|
||||||
cb.invalidCommand(self, self.msg, self.args)
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
assert len(cbs) == 1
|
assert len(cbs) == 1
|
||||||
|
Loading…
Reference in New Issue
Block a user