SedRegex: abort when a search times out

This requires commit b54d8f8073, which separates the timeout and no match cases.

Also, raise the default processTimeout as the plugin now aborts on the first message that times out.

From: e5af479939
This commit is contained in:
James Lu 2019-10-17 21:55:37 -07:00
parent 43d4861577
commit 1267d6452e
2 changed files with 12 additions and 5 deletions

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2015, Michael Daniel Telatynski <postmaster@webdevguru.co.uk>
# Copyright (c) 2015, James Lu <glolol@overdrivenetworks.com>
# Copyright (c) 2015-2019, James Lu <james@overdrivenetworks.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -57,7 +57,7 @@ conf.registerChannelValue(SedRegex, 'ignoreRegex',
registry.Boolean(True, _("""Should Perl/sed regex replacing
ignore messages which look like valid regex?""")))
conf.registerGlobalValue(SedRegex, 'processTimeout',
registry.PositiveFloat(0.05, _("""Sets the timeout when processing a single
registry.PositiveFloat(0.5, _("""Sets the timeout when processing a single
regexp. The default should be adequate unless
you have a busy or low-powered system that
cannot process regexps quickly enough. However,

View File

@ -1,6 +1,6 @@
###
# Copyright (c) 2015, Michael Daniel Telatynski <postmaster@webdevguru.co.uk>
# Copyright (c) 2015-2017, James Lu <james@overdrivenetworks.com>
# Copyright (c) 2015-2019, James Lu <james@overdrivenetworks.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -154,8 +154,9 @@ class SedRegex(callbacks.PluginRegexp):
messageprefix = '%s thinks %s' % (msg.nick, m.nick)
try:
regex_timeout = self.registryValue('processTimeout')
if regexp_wrapper(text, pattern, timeout=regex_timeout, plugin_name=self.name(),
fcn_name='replacer'):
replace_result = regexp_wrapper(text, pattern, timeout=regex_timeout, plugin_name=self.name(),
fcn_name='replacer')
if replace_result is True:
if self.registryValue('boldReplacementText', msg.args[0]):
replacement = ircutils.bold(replacement)
subst = process(pattern.sub, replacement,
@ -168,6 +169,12 @@ class SedRegex(callbacks.PluginRegexp):
irc.reply(_("%s meant to say: %s") %
(messageprefix, subst), prefixNick=False)
return
elif replace_result is None:
# Abort on timeout instead of looking against older messages - this prevents
# replacing the wrong message when we get a one off timeout, which usually leads
# to very confusing results.
# This requires commit https://github.com/ProgVal/Limnoria/commit/b54d8f8073b4fca1787012b211337dc707cfea45
irc.error(_("Search timed out."), Raise=True)
except Exception as e:
self.log.warning(_("SedRegex error: %s"), e, exc_info=True)
if self.registryValue('displayErrors', msg.args[0]):