support sed ampersand syntax

This commit is contained in:
jesopo 2019-09-08 11:18:08 +01:00
parent a59afb883a
commit 9e0934a47e

View file

@ -6,6 +6,7 @@ from src import ModuleManager, utils
REGEX_SPLIT = re.compile("(?<!\\\\)/") REGEX_SPLIT = re.compile("(?<!\\\\)/")
REGEX_SED = re.compile("^(?:(\\S+)[:,] )?s/") REGEX_SED = re.compile("^(?:(\\S+)[:,] )?s/")
SED_AMPERSAND = re.compile(r"((?:^|[^\\])(?:\\\\)*)&")
@utils.export("channelset", @utils.export("channelset",
utils.BoolSetting("sed","Disable/Enable sed in a channel")) utils.BoolSetting("sed","Disable/Enable sed in a channel"))
@ -50,7 +51,6 @@ class Module(ModuleManager.BaseModule):
traceback.print_exc() traceback.print_exc()
event["stderr"].write("Invalid regex in pattern") event["stderr"].write("Invalid regex in pattern")
return return
replace = utils.irc.bold(sed_split[2].replace("\\/", "/"))
for_user = event["match"].group(1) for_user = event["match"].group(1)
if self._closest_setting(event, "sed-sender-only", False): if self._closest_setting(event, "sed-sender-only", False):
@ -61,6 +61,11 @@ class Module(ModuleManager.BaseModule):
for_user=for_user, not_pattern=REGEX_SED) for_user=for_user, not_pattern=REGEX_SED)
if match: if match:
replace = sed_split[2]
replace = replace.replace("\\/", "/")
replace = re.sub(SED_AMPERSAND, match.match, replace)
replace = utils.irc.bold(replace)
new_message = re.sub(pattern, replace, match.line.message, new_message = re.sub(pattern, replace, match.line.message,
count) count)
if match.line.action: if match.line.action: