mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +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
|
||||
self._updateRank(channel, regexp)
|
||||
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)
|
||||
actions.append(thisaction)
|
||||
if max_triggers != 0 and max_triggers == len(actions):
|
||||
|
@ -64,6 +64,26 @@ class MessageParserTestCase(ChannelPluginTestCase):
|
||||
world.testing = True
|
||||
self.prefix = origuser
|
||||
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):
|
||||
self.assertNotError('messageparser add "stuff" "echo i saw some stuff"')
|
||||
|
Loading…
x
Reference in New Issue
Block a user