diff --git a/files/classes/comment.py b/files/classes/comment.py index 2dc3e38c4..83eed8d07 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -341,7 +341,7 @@ class Comment(Base): if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") if v and v.controversial: - for i in re.finditer('(/comments/.*?)"', body, flags=re.A): + for i in controversial_regex.finditer(body): url = i.group(1) p = urlparse(url).query p = parse_qs(p) @@ -395,24 +395,7 @@ class Comment(Base): if not body: return "" - body = censor_slurs(body, v) - - if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com") - - if v and v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net") - - if v and v.controversial: - for i in re.finditer('(/comments/.*?)"', body, flags=re.A): - url = i.group(1) - p = urlparse(url).query - p = parse_qs(p) - - if 'sort' not in p: p['sort'] = ['controversial'] - - url_noquery = url.split('?')[0] - body = body.replace(url, f"{url_noquery}?{urlencode(p, True)}") - - return body + return censor_slurs(body, v) def print(self): print(f'post: {self.id}, comment: {self.author_id}', flush=True) diff --git a/files/helpers/const.py b/files/helpers/const.py index 9c90c5f28..d37719608 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -665,12 +665,17 @@ valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A) query_regex = re.compile("(\w+):(\S+)", flags=re.A) poll_regex = re.compile("\s*\$\$([^\$\n]+)\$\$\s*", flags=re.A) +bet_regex = re.compile("\s*\$\$\$([^\$\n]+)\$\$\$\s*", flags=re.A) choice_regex = re.compile("\s*&&([^\$\n]+)&&\s*", flags=re.A) embed_removing_regex = re.compile('!\[\]\((.*?)\)', flags=re.A) title_regex = re.compile("[^\w ]", flags=re.A) +based_regex = re.compile("based and (.{1,20}?)(-| )pilled", flags=re.I|re.A) + +controversial_regex = re.compile('(/comments/.*?)"', flags=re.A) + slur_regex = re.compile(rf"((?<=\s|>)|^)({single_words})((?=[\s<,.$]|s[\s<,.$]))", flags=re.I|re.A) slur_regex_upper = re.compile(rf"((?<=\s|>)|^)({single_words.upper()})((?=[\s<,.$]|S[\s<,.$]))", flags=re.A) torture_regex = re.compile('(^|\s|\n)(i|me) ', flags=re.I|re.A) diff --git a/files/routes/comments.py b/files/routes/comments.py index f824390e9..7797fce2a 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -413,7 +413,7 @@ def api_comment(v): g.db.add(c_choice) if request.host == 'pcmemes.net' and c.body.lower().startswith("based"): - pill = re.match("based and (.{1,20}?)(-| )pilled", body, flags=re.I|re.A) + pill = based_regex.match(body) if level == 1: basedguy = get_account(parent_post.author_id) else: basedguy = get_account(c.parent_comment.author_id) diff --git a/files/routes/posts.py b/files/routes/posts.py index b877b7c7e..b6d6b04be 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -1030,7 +1030,7 @@ def submit_post(v, sub=None): if v and v.admin_level > 2: bet_options = [] - for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, flags=re.A): + for i in bet_regex.finditer(body): bet_options.append(i.group(1)) body = body.replace(i.group(0), "")