diff --git a/plugins/Conditional/plugin.py b/plugins/Conditional/plugin.py index 921e65732..04e953579 100644 --- a/plugins/Conditional/plugin.py +++ b/plugins/Conditional/plugin.py @@ -299,11 +299,11 @@ class Conditional(callbacks.Plugin): irc.reply('false') nle = wrap(nle, ['float', 'float']) - def iferror(self, irc, msg, args, testcommand, ifcommand, elsecommand): - """ + def cerror(self, irc, msg, args, testcommand): + """ - Runs if raises an error, runs - otherwise. + Runs and returns true if it raises an error; + false otherwise. """ tokens = callbacks.tokenize(testcommand) InvalidCommand = collections.namedtuple('InvalidCommand', @@ -330,12 +330,10 @@ class Conditional(callbacks.Plugin): pass # TODO: do something with the results if errors: - tokens = callbacks.tokenize(ifcommand) - self.Proxy(irc, msg, tokens) + irc.reply('true') else: - tokens = callbacks.tokenize(elsecommand) - self.Proxy(irc, msg, tokens) - iferror = wrap(iferror, ['something', 'something', 'something']) + irc.reply('false') + cerror = wrap(cerror, ['something']) Condition = internationalizeDocstring(Conditional) diff --git a/plugins/Conditional/test.py b/plugins/Conditional/test.py index 562a324a0..fec246528 100644 --- a/plugins/Conditional/test.py +++ b/plugins/Conditional/test.py @@ -147,26 +147,9 @@ class ConditionalTestCase(PluginTestCase): self.assertError('nle 1 bla') def testIferror(self): - self.assertResponse( - 'iferror "echo hi" "foo" "bar"', - 'Error: "bar" is not a valid command.') - self.assertResponse( - 'iferror "echo hi" "echo 1 error" "echo 0 errors"', - '0 errors') - self.assertResponse( - 'iferror "foobarbaz" "echo 1 error" "echo 0 errors"', - '1 error') - self.assertResponse( - 'iferror "help foobarbaz" "echo 1 error" "echo 0 errors"', - '1 error') - self.assertResponse( - r'iferror "iferror \"help foobarbaz\" \"echo hi\" \"foobarbaz\"" ' - r'"foo" "bar"', - 'Error: "bar" is not a valid command.') - self.assertResponse( - r'iferror "iferror \"help foobarbaz\" \"echo hi\" \"foobarbaz\"" ' - r'"echo 0 errors" "echo 1 error"', - '1 error') + self.assertResponse('cerror "echo hi"', 'false') + self.assertResponse('cerror "foobarbaz"', 'true') + self.assertResponse('cerror "help foobarbaz"', 'true') # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: