Properly handle noReplies() in nested commands.

This fix prevents the bot from replying 'Error: I tried to send you an empty message'
when 'utilities ignore' is called from an Aka.
This commit is contained in:
Valentin Lorentz 2017-10-21 15:37:43 +02:00
parent eaa5a5523e
commit 543edccd41
4 changed files with 19 additions and 6 deletions

View File

@ -206,6 +206,11 @@ class AkaChannelTestCase(ChannelPluginTestCase):
self.assertResponse('a+ spam echo egg', 'The operation succeeded.')
self.assertResponse('spam', 'egg')
def testIgnore(self):
self.assertResponse('aka add test ignore', 'The operation succeeded.')
self.assertNoResponse('test')
class AkaTestCase(PluginTestCase):
plugins = ('Aka', 'Alias', 'User', 'Utilities')

View File

@ -49,11 +49,8 @@ class Utilities(callbacks.Plugin):
Does nothing. Useful sometimes for sequencing commands when you don't
care about their non-error return values.
"""
if irc.nested:
msg.tag('ignored')
# Need to call NestedCommandsIrcProxy.reply to continue evaluation
# of the remaining nested commands.
irc.reply('')
irc.noReply()
# Do be careful not to wrap this unless you do any('something').
@internationalizeDocstring

View File

@ -37,6 +37,7 @@ class UtilitiesTestCase(PluginTestCase):
def testIgnore(self):
self.assertNoResponse('utilities ignore foo bar baz', 1)
self.assertError('utilities ignore [re m/foo bar]')
self.assertResponse('echo [utilities ignore foobar] qux', 'qux')
def testSuccess(self):
self.assertNotError('success 1')

View File

@ -498,7 +498,7 @@ class RichReplyMethods(object):
msg = self.reply(prefixer(s), **kwargs)
return msg
def noReply(self):
def noReply(self, msg=None):
self.repliedTo = True
def _error(self, s, Raise=False, **kwargs):
@ -1011,6 +1011,16 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
self.args[self.counter] = s
self.evalArgs()
def noReply(self, msg=None):
if msg is None:
msg = self.msg
if self.finalEvaled:
self.irc.noReply(msg=msg)
else:
self.args.pop(self.counter)
msg.tag('ignored', False)
self.evalArgs()
def replies(self, L, prefixer=None, joiner=None,
onlyPrefixFirst=False, to=None,
oneToOne=None, **kwargs):