mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-28 22:41:05 -05:00
SedRegex: Avoid pickling the Irc object
This commit is contained in:
parent
3bb77a7082
commit
5e24dc9ed3
@ -56,11 +56,11 @@ axe_spaces = utils.str.MultipleReplacer({'\n': '\\n', '\t': '\\t', '\r': '\\r'})
|
|||||||
class SearchNotFoundError(Exception):
|
class SearchNotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _replacer_process(irc, msg, target, pattern, replacement, count,
|
def _replacer_process(msg, target, pattern, replacement, count,
|
||||||
messages, config, log):
|
messages, historyLength, config, log):
|
||||||
for m in messages:
|
for m in messages:
|
||||||
if m.command in ('PRIVMSG', 'NOTICE') and \
|
if m.command in ('PRIVMSG', 'NOTICE') and \
|
||||||
ircutils.strEqual(m.args[0], msg.args[0]) and m.tagged('receivedBy') == irc:
|
ircutils.strEqual(m.args[0], msg.args[0]):
|
||||||
if target and m.nick != target:
|
if target and m.nick != target:
|
||||||
continue
|
continue
|
||||||
# Don't snarf ignored users' messages unless specifically
|
# Don't snarf ignored users' messages unless specifically
|
||||||
@ -104,14 +104,14 @@ def _replacer_process(irc, msg, target, pattern, replacement, count,
|
|||||||
fmt = config['format.other']
|
fmt = config['format.other']
|
||||||
env = {'otherNick': msg.nick, 'replacement': subst}
|
env = {'otherNick': msg.nick, 'replacement': subst}
|
||||||
|
|
||||||
return ircutils.standardSubstitute(irc, m, fmt, env)
|
return (m, fmt, env)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(_("SedRegex error: %s"), e, exc_info=True)
|
log.warning(_("SedRegex error: %s"), e, exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
log.debug(_("SedRegex: Search %r not found in the last %i messages of %s."),
|
log.debug(_("SedRegex: Search %r not found in the last %i messages of %s."),
|
||||||
msg.args[1], len(irc.state.history), msg.args[0])
|
msg.args[1], historyLength, msg.args[0])
|
||||||
raise SearchNotFoundError()
|
raise SearchNotFoundError()
|
||||||
|
|
||||||
class SedRegex(callbacks.PluginRegexp):
|
class SedRegex(callbacks.PluginRegexp):
|
||||||
@ -233,6 +233,8 @@ class SedRegex(callbacks.PluginRegexp):
|
|||||||
if not ircutils.isNick(str(target)):
|
if not ircutils.isNick(str(target)):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
iterable = [m for m in iterable if m.tagged('receivedBy') == irc]
|
||||||
|
|
||||||
regex_timeout = self.registryValue('processTimeout')
|
regex_timeout = self.registryValue('processTimeout')
|
||||||
config = {
|
config = {
|
||||||
key: self.registryValue(key, msg.channel, irc.network)
|
key: self.registryValue(key, msg.channel, irc.network)
|
||||||
@ -240,11 +242,13 @@ class SedRegex(callbacks.PluginRegexp):
|
|||||||
'format.other')
|
'format.other')
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
message = process(_replacer_process, irc, msg,
|
(m, fmt, env) = process(_replacer_process, msg,
|
||||||
target=target, pattern=pattern, replacement=replacement,
|
target=target, pattern=pattern, replacement=replacement,
|
||||||
count=count, messages=iterable,
|
count=count, messages=iterable,
|
||||||
|
historyLength=len(irc.state.history),
|
||||||
config=config, log=self.log,
|
config=config, log=self.log,
|
||||||
timeout=regex_timeout, pn=self.name(), cn='replacer')
|
timeout=regex_timeout, pn=self.name(), cn='replacer')
|
||||||
|
message = ircutils.standardSubstitute(irc, m, fmt, env)
|
||||||
except ProcessTimeoutError:
|
except ProcessTimeoutError:
|
||||||
irc.error(_("Search timed out."))
|
irc.error(_("Search timed out."))
|
||||||
except SearchNotFoundError:
|
except SearchNotFoundError:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user