diff --git a/files/helpers/regex.py b/files/helpers/regex.py index fef4e496b..fec1186ba 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -58,8 +58,11 @@ snappy_youtube_regex = re.compile(']*>|{slur_single_words}", flags=re.I|re.A) +slur_regex_title = re.compile(f"<[^>]*>|{slur_single_words.title()}", flags=re.A) slur_regex_upper = re.compile(f"<[^>]*>|{slur_single_words.upper()}", flags=re.A) + profanity_regex = re.compile(f"<[^>]*>|{profanity_single_words}", flags=re.I|re.A) +profanity_regex_title = re.compile(f"<[^>]*>|{profanity_single_words.title()}", flags=re.A) profanity_regex_upper = re.compile(f"<[^>]*>|{profanity_single_words.upper()}", flags=re.A) torture_regex = re.compile('(^|\s)(i|me)($|\s)', flags=re.I|re.A) @@ -151,15 +154,17 @@ pronouns_regex = re.compile("([a-z]{1,7})\/[a-z]{1,7}(\/[a-z]{1,7})?", flags=re. html_title_regex = re.compile("(.{1,200})", flags=re.I) -def sub_matcher(match, upper=False, replace_with=SLURS_FOR_REPLACING): +def sub_matcher(match, upper=False, title=False, replace_with=SLURS_FOR_REPLACING): group_num = 0 match_str = match.group(group_num) if match_str.startswith('<'): return match_str else: repl = replace_with[match_str.lower()] - if not upper or "' in body or '' in body: return body - def replace_re(body, regex, regex_upper, sub_func, sub_func_upper): - body = regex_upper.sub(sub_func_upper, body) - return regex.sub(sub_func, body) - if not logged_user or logged_user == 'chat' or logged_user.slurreplacer: - body = replace_re(body, slur_regex, slur_regex_upper, sub_matcher_slurs, sub_matcher_slurs_upper) + body = replace_re(body, slur_regex, slur_regex_title, slur_regex_upper, sub_matcher_slurs, sub_matcher_slurs_title, sub_matcher_slurs_upper) + if SITE_NAME == 'rDrama': if not logged_user or logged_user == 'chat' or logged_user.profanityreplacer: - body = replace_re(body, profanity_regex, profanity_regex_upper, sub_matcher_profanities, sub_matcher_profanities_upper) + body = replace_re(body, profanity_regex, profanity_regex_title, profanity_regex_upper, sub_matcher_profanities, sub_matcher_profanities_title, sub_matcher_profanities_upper) return body