diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 35e44cca0..224723383 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -132,9 +132,7 @@ def torture_ap(body, username): lines[i] = torture_regex.sub(rf'\1@{username} ', lines[i]) lines[i] = torture_regex2.sub(rf'\1@{username} is ', lines[i]) - body = ''.join(lines) + '\n:#trumpjaktalking:' - - return body + return ''.join(lines).strip() commands = { diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 2f8422c04..885e59ea4 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -193,9 +193,13 @@ def with_sigalrm_timeout(timeout: int): @with_sigalrm_timeout(2) -def sanitize(sanitized, edit=False, limit_pings=0, showmore=True, marsified=False): +def sanitize(sanitized, edit=False, limit_pings=0, showmore=True, marsified=False, torture=False): sanitized = sanitized.strip() + if torture: + sanitized = torture_ap(sanitized, g.v.username) + sanitized += '\n:#trumpjaktalking:' + sanitized = normalize_url(sanitized) if '```' not in sanitized and '
' not in sanitized: @@ -399,7 +403,11 @@ def allowed_attributes_emojis(tag, name, value): @with_sigalrm_timeout(1) -def filter_emojis_only(title, edit=False, graceful=False): +def filter_emojis_only(title, edit=False, graceful=False, torture=False): + title = title.strip() + + if torture: + title = torture_ap(title, g.v.username) title = title.replace('','').replace('','').replace("\ufeff", "").replace("𒐪","").replace("\n", "").replace("\r", "").replace("\t", "").replace("&", "&").replace('<','<').replace('>','>').replace('"', '"').replace("'", "'").strip() diff --git a/files/routes/comments.py b/files/routes/comments.py index a006a61f2..e7e60a270 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -332,16 +332,15 @@ def comment(v): with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f: f.write('\n{[para]}\n' + body) - if v.agendaposter and not v.marseyawarded and parent_post.id not in ADMIGGERS and parent_post.sub != 'chudrama': - body = torture_ap(body, v.username) - body_for_sanitize = body if v.owoify: body_for_sanitize = owoify(body_for_sanitize) if v.marsify: body_for_sanitize = marsify(body_for_sanitize) - body_html = sanitize(body_for_sanitize, limit_pings=5, marsified=True) + torture = (v.agendaposter and not v.marseyawarded and parent_post.sub != 'chudrama' and parent_post.id not in ADMIGGERS) + + body_html = sanitize(body_for_sanitize, limit_pings=5, marsified=True, torture=torture) if parent_post.id not in ADMIGGERS and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower(): @@ -707,9 +706,6 @@ def edit_comment(cid, v): elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403 - if v.agendaposter and not v.marseyawarded and c.post.sub != 'chudrama': - body = torture_ap(body, v.username) - for i in poll_regex.finditer(body): body = body.replace(i.group(0), "") option = CommentOption( @@ -772,7 +768,9 @@ def edit_comment(cid, v): if v.marsify: body_for_sanitize = marsify(body_for_sanitize) - body_html = sanitize(body_for_sanitize, edit=True, limit_pings=5, marsified=True) + torture = (v.agendaposter and not v.marseyawarded and c.post.sub != 'chudrama') + + body_html = sanitize(body_for_sanitize, edit=True, limit_pings=5, marsified=True, torture=torture) if len(body_html) > 20000: abort(400) diff --git a/files/routes/posts.py b/files/routes/posts.py index 740218418..288228a60 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -405,10 +405,9 @@ def edit_post(pid, v): return {"error":"You have to type less than 140 characters!"}, 403 if title != p.title: - if v.id == p.author_id and v.agendaposter and not v.marseyawarded and p.sub != 'chudrama': - title = torture_ap(title, v.username) + torture = (v.agendaposter and not v.marseyawarded and p.sub != 'chudrama' and v.id == p.author_id) - title_html = filter_emojis_only(title, edit=True) + title_html = filter_emojis_only(title, edit=True, torture=torture) if v.id == p.author_id and v.marseyawarded and not marseyaward_title_regex.fullmatch(title_html): return {"error":"You can only type marseys!"}, 403 @@ -421,9 +420,6 @@ def edit_post(pid, v): body = body.strip() if body != p.body: - if v.id == p.author_id and v.agendaposter and not v.marseyawarded and p.sub != 'chudrama': - body = torture_ap(body, v.username) - for i in poll_regex.finditer(body): body = body.replace(i.group(0), "") option = SubmissionOption( @@ -443,7 +439,9 @@ def edit_post(pid, v): g.db.add(option) - body_html = sanitize(body, edit=True, limit_pings=100, showmore=False) + torture = (v.agendaposter and not v.marseyawarded and p.sub != 'chudrama' and v.id == p.author_id) + + body_html = sanitize(body, edit=True, limit_pings=100, showmore=False, torture=torture) if v.id == p.author_id and v.marseyawarded and marseyaward_body_regex.search(body_html): return {"error":"You can only type marseys!"}, 403 @@ -721,10 +719,9 @@ def submit_post(v, sub=None): if v.is_suspended: return error("You can't perform this action while banned.") - if v.agendaposter and not v.marseyawarded and sub != 'chudrama': - title = torture_ap(title, v.username) + torture = (v.agendaposter and not v.marseyawarded and sub != 'chudrama') - title_html = filter_emojis_only(title, graceful=True) + title_html = filter_emojis_only(title, graceful=True, torture=torture) if v.marseyawarded and not marseyaward_title_regex.fullmatch(title_html): return error("You can only type marseys!") @@ -892,14 +889,13 @@ def submit_post(v, sub=None): choices.append(i.group(1)) body = body.replace(i.group(0), "") - if v.agendaposter and not v.marseyawarded and sub != 'chudrama': - body = torture_ap(body, v.username) - body += process_files() body = body.strip() - body_html = sanitize(body, limit_pings=100, showmore=False) + torture = (v.agendaposter and not v.marseyawarded and sub != 'chudrama') + + body_html = sanitize(body, limit_pings=100, showmore=False, torture=torture) if v.marseyawarded and marseyaward_body_regex.search(body_html): return error("You can only type marseys!")