mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-21 08:01:00 +01:00
MessageParser: Prevent empty matches from leaving unreplaced.
This commit is contained in:
parent
b28f72fcee
commit
417f38b8c1
@ -175,7 +175,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
thisaction = action
|
thisaction = action
|
||||||
self._updateRank(channel, regexp)
|
self._updateRank(channel, regexp)
|
||||||
for (i, j) in enumerate(match.groups()):
|
for (i, j) in enumerate(match.groups()):
|
||||||
if match.group(i+1):
|
if match.group(i+1) is not None:
|
||||||
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
|
thisaction = re.sub(r'\$' + str(i+1), match.group(i+1), thisaction)
|
||||||
actions.append(thisaction)
|
actions.append(thisaction)
|
||||||
if max_triggers != 0 and max_triggers == len(actions):
|
if max_triggers != 0 and max_triggers == len(actions):
|
||||||
|
@ -65,6 +65,26 @@ class MessageParserTestCase(ChannelPluginTestCase):
|
|||||||
self.prefix = origuser
|
self.prefix = origuser
|
||||||
conf.supybot.plugins.MessageParser.requireManageCapability.setValue(origconf)
|
conf.supybot.plugins.MessageParser.requireManageCapability.setValue(origconf)
|
||||||
|
|
||||||
|
def testGroups(self):
|
||||||
|
self.assertNotError('messageparser add "this (.+) a(.*)" "echo $1 $2"')
|
||||||
|
self.feedMsg('this is a foo')
|
||||||
|
self.assertResponse(' ', 'is foo')
|
||||||
|
self.feedMsg('this is a')
|
||||||
|
self.assertResponse(' ', 'is')
|
||||||
|
self.assertNotError('messageparser remove "this (.+) a(.*)"')
|
||||||
|
self.assertNotError('messageparser add "this (.+) a(.*)" "echo $1"')
|
||||||
|
self.feedMsg('this is a foo')
|
||||||
|
self.assertResponse(' ', 'is')
|
||||||
|
self.feedMsg('this is a')
|
||||||
|
self.assertResponse(' ', 'is')
|
||||||
|
self.assertNotError('messageparser remove "this (.+) a(.*)"')
|
||||||
|
self.assertNotError('messageparser add "this( .+)? a(.*)" "echo $1 $2"')
|
||||||
|
self.feedMsg('this a foo')
|
||||||
|
self.assertResponse(' ', '$1 foo')
|
||||||
|
self.feedMsg('this a')
|
||||||
|
self.assertResponse(' ', '$1')
|
||||||
|
self.assertNotError('messageparser remove "this( .+)? a(.*)"')
|
||||||
|
|
||||||
def testShow(self):
|
def testShow(self):
|
||||||
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
|
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
|
||||||
self.assertRegexp('messageparser show "nostuff"', 'there is no such regexp trigger')
|
self.assertRegexp('messageparser show "nostuff"', 'there is no such regexp trigger')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user