mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-09 02:54:13 +01:00
Made the last test pass.
This commit is contained in:
parent
d470488788
commit
912fb78afb
37
src/Misc.py
37
src/Misc.py
@ -70,33 +70,20 @@ class Misc(callbacks.Privmsg):
|
|||||||
# This exists to be able to respond to attempts to command the bot
|
# This exists to be able to respond to attempts to command the bot
|
||||||
# with a "That's not a command!" if the proper conf.variable is set.
|
# with a "That's not a command!" if the proper conf.variable is set.
|
||||||
callbacks.Privmsg.doPrivmsg(self, irc, msg)
|
callbacks.Privmsg.doPrivmsg(self, irc, msg)
|
||||||
if conf.replyWhenNotCommand and msg.nick != irc.nick:
|
|
||||||
s = callbacks.addressed(irc.nick, msg)
|
|
||||||
if s:
|
|
||||||
for cb in irc.callbacks:
|
|
||||||
if isinstance(cb, callbacks.PrivmsgRegexp) or \
|
|
||||||
isinstance(cb, callbacks.PrivmsgCommandAndRegexp):
|
|
||||||
for (r, _) in cb.res:
|
|
||||||
if r.search(msg.args[1]):
|
|
||||||
return
|
|
||||||
if hasattr(cb, 'addressedRes'):
|
|
||||||
for (r, _) in cb.addressedRes:
|
|
||||||
if r.search(s):
|
|
||||||
return
|
|
||||||
notCommands = []
|
notCommands = []
|
||||||
ambiguousCommands = {}
|
ambiguousCommands = {}
|
||||||
|
s = callbacks.addressed(irc.nick, msg)
|
||||||
|
if s:
|
||||||
tokens = callbacks.tokenize(s)
|
tokens = callbacks.tokenize(s)
|
||||||
for command in callbacks.getCommands(tokens):
|
commands = callbacks.getCommands(tokens)
|
||||||
|
for command in commands:
|
||||||
command = callbacks.canonicalName(command)
|
command = callbacks.canonicalName(command)
|
||||||
cbs = callbacks.findCallbackForCommand(irc, command)
|
cbs = callbacks.findCallbackForCommand(irc, command)
|
||||||
if not cbs:
|
if not cbs:
|
||||||
notCommands.append(command)
|
notCommands.append(command)
|
||||||
elif len(cbs) > 1:
|
elif len(cbs) > 1:
|
||||||
ambiguousCommands[command] = [cb.name() for cb in cbs]
|
ambiguousCommands[command] = [cb.name() for cb in cbs]
|
||||||
if notCommands:
|
if ambiguousCommands:
|
||||||
irc = callbacks.IrcObjectProxyRegexp(irc)
|
|
||||||
replyWhenNotCommand(irc, msg, notCommands)
|
|
||||||
elif ambiguousCommands:
|
|
||||||
if len(ambiguousCommands) == 1: # Common case.
|
if len(ambiguousCommands) == 1: # Common case.
|
||||||
(command, cbs) = ambiguousCommands.popitem()
|
(command, cbs) = ambiguousCommands.popitem()
|
||||||
s = 'The command %r is available in the plugins %s. '\
|
s = 'The command %r is available in the plugins %s. '\
|
||||||
@ -113,6 +100,20 @@ class Misc(callbacks.Privmsg):
|
|||||||
s = '%s; please specify from which plugins to ' \
|
s = '%s; please specify from which plugins to ' \
|
||||||
'call these commands.' % '; '.join(L)
|
'call these commands.' % '; '.join(L)
|
||||||
irc.queueMsg(callbacks.reply(msg, 'Error: ' + s))
|
irc.queueMsg(callbacks.reply(msg, 'Error: ' + s))
|
||||||
|
return
|
||||||
|
if conf.replyWhenNotCommand and msg.nick!=irc.nick and notCommands:
|
||||||
|
for cb in irc.callbacks:
|
||||||
|
if isinstance(cb, callbacks.PrivmsgRegexp) or \
|
||||||
|
isinstance(cb, callbacks.PrivmsgCommandAndRegexp):
|
||||||
|
for (r, _) in cb.res:
|
||||||
|
if r.search(msg.args[1]):
|
||||||
|
return
|
||||||
|
if hasattr(cb, 'addressedRes'):
|
||||||
|
for (r, _) in cb.addressedRes:
|
||||||
|
if r.search(s):
|
||||||
|
return
|
||||||
|
irc = callbacks.IrcObjectProxyRegexp(irc)
|
||||||
|
replyWhenNotCommand(irc, msg, notCommands)
|
||||||
|
|
||||||
def list(self, irc, msg, args):
|
def list(self, irc, msg, args):
|
||||||
"""[--private] [<module name>]
|
"""[--private] [<module name>]
|
||||||
|
@ -234,6 +234,7 @@ class PrivmsgTestCase(ChannelPluginTestCase):
|
|||||||
|
|
||||||
def testAmbiguousError(self):
|
def testAmbiguousError(self):
|
||||||
self.irc.addCallback(self.First())
|
self.irc.addCallback(self.First())
|
||||||
|
self.assertNotError('firstcmd')
|
||||||
self.irc.addCallback(self.FirstRepeat())
|
self.irc.addCallback(self.FirstRepeat())
|
||||||
self.assertError('firstcmd')
|
self.assertError('firstcmd')
|
||||||
self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)')
|
self.assertNotRegexp('firstcmd', '(foo.*baz|baz.*foo)')
|
||||||
|
Loading…
Reference in New Issue
Block a user