diff --git a/plugins/MessageParser/config.py b/plugins/MessageParser/config.py index 27dc241be..e3528aa7a 100644 --- a/plugins/MessageParser/config.py +++ b/plugins/MessageParser/config.py @@ -76,5 +76,8 @@ conf.registerChannelValue(MessageParser, 'requireManageCapability', conf.registerChannelValue(MessageParser, 'listSeparator', registry.String(', ', _("""Determines the separator used between regexps when shown by the list command."""))) +conf.registerChannelValue(MessageParser, 'maxTriggers', + registry.Integer(0, _("""Determines the maximum number of triggers in + one message. Set this to 0 to allow an infinite number of triggers."""))) # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index 94d2374b6..78a35d48b 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -167,6 +167,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): results.extend(map(lambda x: (channel,)+x, cursor.fetchall())) if len(results) == 0: return + max_triggers = self.registryValue('maxTriggers', channel) for (channel, regexp, action) in results: for match in re.finditer(regexp, msg.args[1]): if match is not None: @@ -175,6 +176,11 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): for (i, j) in enumerate(match.groups()): thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction) actions.append(thisaction) + if max_triggers != 0 and max_triggers == len(actions): + break + if max_triggers != 0 and max_triggers == len(actions): + break + for action in actions: self._runCommandFunction(irc, msg, action) diff --git a/plugins/MessageParser/test.py b/plugins/MessageParser/test.py index 870f83ebd..63c59e2f1 100644 --- a/plugins/MessageParser/test.py +++ b/plugins/MessageParser/test.py @@ -90,6 +90,22 @@ class MessageParserTestCase(ChannelPluginTestCase): m = self.getMsg(' ') self.failUnless(str(m).startswith('PRIVMSG #test :i saw some stuff')) + def testMaxTriggers(self): + self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') + self.assertNotError('messageparser add "sbd" "echo i saw somebody"') + self.feedMsg('this message issued by sbd has some stuff in it') + m = self.getMsg(' ') + self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) + m = self.getMsg(' ') + self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) + + with conf.supybot.plugins.messageparser.maxtriggers.context(1): + self.feedMsg('this message issued by sbd has some stuff in it') + m = self.getMsg(' ') + self.failUnless(str(m).startswith('PRIVMSG #test :i saw some')) + m = self.getMsg(' ') + self.failIf(m) + def testLock(self): self.assertNotError('messageparser add "stuff" "echo i saw some stuff"') self.assertNotError('messageparser lock "stuff"')