Conditional: Add --case-insensitive switch to @match.

This commit is contained in:
Valentin Lorentz 2013-08-04 08:35:15 +02:00
parent f7f003a8a0
commit 1e8dddaa6a
2 changed files with 12 additions and 3 deletions

View File

@ -200,17 +200,24 @@ class Conditional(callbacks.Plugin):
le = wrap(le, ['anything', 'anything'])
@internationalizeDocstring
def match(self, irc, msg, args, item1, item2):
"""<item1> <item2>
def match(self, irc, msg, args, optlist, item1, item2):
"""[--case-insensitive] <item1> <item2>
Determines if <item1> is a substring of <item2>.
Returns true if <item1> is contained in <item2>.
Will only match case if --case-insensitive is not given.
"""
optlist = dict(optlist)
if 'case-insensitive' in optlist:
item1 = item1.lower()
item2 = item2.lower()
if item2.find(item1) != -1:
irc.reply('true')
else:
irc.reply('false')
match = wrap(match, ['something', 'something'])
match = wrap(match, [getopts({'case-insensitive': ''}),
'something', 'something'])
@internationalizeDocstring
def nceq(self, irc, msg, args, item1, item2):

View File

@ -98,6 +98,8 @@ class ConditionalTestCase(PluginTestCase):
def testMatch(self):
self.assertRegexp('match bla mooblafoo', 'true')
self.assertRegexp('match bla mooblfoo', 'false')
self.assertRegexp('match Bla moobLafoo', 'false')
self.assertRegexp('match --case-insensitive Bla moobLafoo', 'true')
self.assertError('match bla bla stuff')
def testNceq(self):