MessageParser: Log and skip current regexp on error

This commit is contained in:
Valentin Lorentz 2023-09-22 13:30:08 +02:00
parent 91accc0458
commit 850b4c3f69

View File

@ -192,20 +192,23 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
return return
max_triggers = self.registryValue('maxTriggers', channel, irc.network) max_triggers = self.registryValue('maxTriggers', channel, irc.network)
for (channel, regexp, action) in results: for (channel, regexp, action) in results:
for match in re.finditer(regexp, msg.args[1]): try:
if match is not None: for match in re.finditer(regexp, msg.args[1]):
thisaction = action if match is not None:
self._updateRank(irc.network, channel, regexp) thisaction = action
for (i, j) in enumerate(match.groups()): self._updateRank(irc.network, channel, regexp)
if match.group(i+1) is not None: for (i, j) in enumerate(match.groups()):
# Need a lambda to prevent re.sub from if match.group(i+1) is not None:
# interpreting backslashes in the replacement # Need a lambda to prevent re.sub from
thisaction = re.sub(r'\$' + str(i+1), lambda _: match.group(i+1), thisaction) # interpreting backslashes in the replacement
actions.append((regexp, thisaction)) thisaction = re.sub(r'\$' + str(i+1), lambda _: match.group(i+1), thisaction)
if max_triggers != 0 and max_triggers == len(actions): actions.append((regexp, thisaction))
break if max_triggers != 0 and max_triggers == len(actions):
if max_triggers != 0 and max_triggers == len(actions): break
break if max_triggers != 0 and max_triggers == len(actions):
break
except Exception:
self.log.exception('Error while handling %r', regexp)
for (regexp, action) in actions: for (regexp, action) in actions: