From 1137d56de7bba19ad5266fab5b1e273adb246d8f Mon Sep 17 00:00:00 2001 From: TLSM <104547575+TLSM@users.noreply.github.com> Date: Thu, 5 May 2022 16:47:13 -0400 Subject: [PATCH] Disable chudtexting in quotes. (#245) Chose to split text into lines because Python regex supports neither variable-width nor infinite-width negative lookbehinds. This precludes a simple pure regex solution. Since all replacements are done at the word level, this has no obvious ill effects. --- files/helpers/const.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 9d0f204cb2..57c0609ced 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -781,6 +781,7 @@ slur_regex = re.compile(f"({single_words})(?![^<]*>)", flags=re.I|re.A) slur_regex_upper = re.compile(f"({single_words.upper()})(?![^<]*>)", flags=re.A) torture_regex = re.compile('(^|\s)(i|me) ', flags=re.I|re.A) torture_regex2 = re.compile("(^|\s)i'm ", flags=re.I|re.A) +torture_regex_exclude = re.compile('^\s*>', flags=re.A) def sub_matcher(match): return SLURS[match.group(0).lower()] @@ -795,11 +796,17 @@ def censor_slurs(body, logged_user): return body def torture_ap(body, username): - for k, l in AJ_REPLACEMENTS.items(): - body = body.replace(k, l) - body = torture_regex.sub(rf'\1@{username} ', body) - body = torture_regex2.sub(rf'\1@{username} is ', body) - return body + lines = body.splitlines(keepends=True) + + for i in range(len(lines)): + if torture_regex_exclude.match(lines[i]): + continue + for k, l in AJ_REPLACEMENTS.items(): + lines[i] = lines[i].replace(k, l) + lines[i] = torture_regex.sub(rf'\1@{username} ', lines[i]) + lines[i] = torture_regex2.sub(rf'\1@{username} is ', lines[i]) + + return ''.join(lines) YOUTUBE_KEY = environ.get("YOUTUBE_KEY", "").strip()