Condition: Add support for integers (casted to booleans).

This commit is contained in:
Valentin Lorentz 2015-11-07 18:44:33 +01:00
parent e1d0c232ea
commit 8bdab5e23e
2 changed files with 10 additions and 4 deletions

View File

@ -53,6 +53,8 @@ else:
_any = __builtins__.any
_all = __builtins__.all
boolean_or_int = first('int', 'boolean')
class Conditional(callbacks.Plugin):
"""This plugin provides logic operators and other commands that
enable you to run commands only if a condition is true. Useful for nested
@ -84,7 +86,7 @@ class Conditional(callbacks.Plugin):
else:
self._runCommandFunction(irc, msg, elsecommand)
irc.noReply()
cif = wrap(cif, ['boolean', 'something', 'something'])
cif = wrap(cif, [boolean_or_int, 'something', 'something'])
@internationalizeDocstring
def cand(self, irc, msg, args, conds):
@ -96,7 +98,7 @@ class Conditional(callbacks.Plugin):
irc.reply("true")
else:
irc.reply("false")
cand = wrap(cand, [many('boolean'),])
cand = wrap(cand, [many(boolean_or_int),])
@internationalizeDocstring
def cor(self, irc, msg, args, conds):
@ -108,7 +110,7 @@ class Conditional(callbacks.Plugin):
irc.reply("true")
else:
irc.reply("false")
cor = wrap(cor, [many('boolean'),])
cor = wrap(cor, [many(boolean_or_int),])
@internationalizeDocstring
def cxor(self, irc, msg, args, conds):
@ -120,7 +122,7 @@ class Conditional(callbacks.Plugin):
irc.reply("true")
else:
irc.reply("false")
cxor = wrap(cxor, [many('boolean'),])
cxor = wrap(cxor, [many(boolean_or_int),])
@internationalizeDocstring
def ceq(self, irc, msg, args, item1, item2):

View File

@ -39,6 +39,10 @@ class ConditionalTestCase(PluginTestCase):
self.assertRegexp('cif [ceq bla bar] "echo moo" "echo foo"', 'foo')
self.assertRegexp('cif [cand [ceq bla bla] [ne soo boo]] "echo moo" "echo foo"', 'moo')
self.assertRegexp('cif [ceq [echo $nick] "test"] "echo yay" "echo nay"', 'yay')
self.assertRegexp('cif 0 "echo nay" "echo yay"', 'yay')
self.assertRegexp('cif 1 "echo yay" "echo nay"', 'yay')
self.assertRegexp('cif 4 "echo yay" "echo nay"', 'yay')
self.assertRegexp('cif -1 "echo yay" "echo nay"', 'yay')
def testCand(self):
self.assertRegexp('cand true true', 'true')