mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 23:54:07 +01:00
Condition: Add support for integers (casted to booleans).
This commit is contained in:
parent
e1d0c232ea
commit
8bdab5e23e
@ -53,6 +53,8 @@ else:
|
|||||||
_any = __builtins__.any
|
_any = __builtins__.any
|
||||||
_all = __builtins__.all
|
_all = __builtins__.all
|
||||||
|
|
||||||
|
boolean_or_int = first('int', 'boolean')
|
||||||
|
|
||||||
class Conditional(callbacks.Plugin):
|
class Conditional(callbacks.Plugin):
|
||||||
"""This plugin provides logic operators and other commands that
|
"""This plugin provides logic operators and other commands that
|
||||||
enable you to run commands only if a condition is true. Useful for nested
|
enable you to run commands only if a condition is true. Useful for nested
|
||||||
@ -84,7 +86,7 @@ class Conditional(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
self._runCommandFunction(irc, msg, elsecommand)
|
self._runCommandFunction(irc, msg, elsecommand)
|
||||||
irc.noReply()
|
irc.noReply()
|
||||||
cif = wrap(cif, ['boolean', 'something', 'something'])
|
cif = wrap(cif, [boolean_or_int, 'something', 'something'])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def cand(self, irc, msg, args, conds):
|
def cand(self, irc, msg, args, conds):
|
||||||
@ -96,7 +98,7 @@ class Conditional(callbacks.Plugin):
|
|||||||
irc.reply("true")
|
irc.reply("true")
|
||||||
else:
|
else:
|
||||||
irc.reply("false")
|
irc.reply("false")
|
||||||
cand = wrap(cand, [many('boolean'),])
|
cand = wrap(cand, [many(boolean_or_int),])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def cor(self, irc, msg, args, conds):
|
def cor(self, irc, msg, args, conds):
|
||||||
@ -108,7 +110,7 @@ class Conditional(callbacks.Plugin):
|
|||||||
irc.reply("true")
|
irc.reply("true")
|
||||||
else:
|
else:
|
||||||
irc.reply("false")
|
irc.reply("false")
|
||||||
cor = wrap(cor, [many('boolean'),])
|
cor = wrap(cor, [many(boolean_or_int),])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def cxor(self, irc, msg, args, conds):
|
def cxor(self, irc, msg, args, conds):
|
||||||
@ -120,7 +122,7 @@ class Conditional(callbacks.Plugin):
|
|||||||
irc.reply("true")
|
irc.reply("true")
|
||||||
else:
|
else:
|
||||||
irc.reply("false")
|
irc.reply("false")
|
||||||
cxor = wrap(cxor, [many('boolean'),])
|
cxor = wrap(cxor, [many(boolean_or_int),])
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def ceq(self, irc, msg, args, item1, item2):
|
def ceq(self, irc, msg, args, item1, item2):
|
||||||
|
@ -39,6 +39,10 @@ class ConditionalTestCase(PluginTestCase):
|
|||||||
self.assertRegexp('cif [ceq bla bar] "echo moo" "echo foo"', 'foo')
|
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 [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 [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):
|
def testCand(self):
|
||||||
self.assertRegexp('cand true true', 'true')
|
self.assertRegexp('cand true true', 'true')
|
||||||
|
Loading…
Reference in New Issue
Block a user