use BufferLine.notes to allow cumulative sed edits

This commit is contained in:
jesopo 2019-11-27 12:59:59 +00:00
parent 40a459a83c
commit b66119ba96

View file

@ -56,20 +56,31 @@ class Module(ModuleManager.BaseModule):
if self._closest_setting(event, "sed-sender-only", False): if self._closest_setting(event, "sed-sender-only", False):
for_user = event["user"].nickname for_user = event["user"].nickname
match_line = None
match = None
match_message = None
with utils.deadline(): with utils.deadline():
match = event["target"].buffer.find(pattern, from_self=False, for line in event["target"].buffer.get_all(for_user):
for_user=for_user, not_pattern=REGEX_SED) if not line.from_self:
message = line.notes.get("sed-line", line.message)
match = pattern.search(message)
if match and not REGEX_SED.match(message):
match_line = line
match = match.group(0)
match_message = message
if match: if match:
replace = sed_split[2] replace = sed_split[2]
replace = replace.replace("\\/", "/") replace = replace.replace("\\/", "/")
replace = re.sub(SED_AMPERSAND, "\\1%s" % match.match, replace) replace = re.sub(SED_AMPERSAND, "\\1%s" % match, replace)
replace = utils.irc.bold(replace) replace_color = utils.irc.bold(replace)
new_message = re.sub(pattern, replace, match.line.message, new_message = re.sub(pattern, replace, message, count)
count) new_message_color = re.sub(pattern, utils.irc.bold(replace),
if match.line.action: message, count)
prefix = "* %s" % match.line.sender if match_line.action:
prefix = "* %s" % match_line.sender
else: else:
prefix = "<%s>" % match.line.sender prefix = "<%s>" % match_line.sender
event["stdout"].write("%s %s" % (prefix, new_message)) match_line.notes["sed-line"] = new_message
event["stdout"].write("%s %s" % (prefix, new_message_color))