mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
MessageParser: Add supybot.MessageParser.maxTriggers variable.
This commit is contained in:
parent
0ef1347bc6
commit
4069b2eba1
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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"')
|
||||
|
Loading…
Reference in New Issue
Block a user