refactor torture_ap

master
Aevann1 2022-09-05 22:05:04 +02:00
parent 26e28efbec
commit 0f232b264c
4 changed files with 27 additions and 27 deletions

View File

@ -132,9 +132,7 @@ def torture_ap(body, username):
lines[i] = torture_regex.sub(rf'\1@{username} ', lines[i]) lines[i] = torture_regex.sub(rf'\1@{username} ', lines[i])
lines[i] = torture_regex2.sub(rf'\1@{username} is ', lines[i]) lines[i] = torture_regex2.sub(rf'\1@{username} is ', lines[i])
body = ''.join(lines) + '\n:#trumpjaktalking:' return ''.join(lines).strip()
return body
commands = { commands = {

View File

@ -193,9 +193,13 @@ def with_sigalrm_timeout(timeout: int):
@with_sigalrm_timeout(2) @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() sanitized = sanitized.strip()
if torture:
sanitized = torture_ap(sanitized, g.v.username)
sanitized += '\n:#trumpjaktalking:'
sanitized = normalize_url(sanitized) sanitized = normalize_url(sanitized)
if '```' not in sanitized and '<pre>' not in sanitized: if '```' not in sanitized and '<pre>' not in sanitized:
@ -399,7 +403,11 @@ def allowed_attributes_emojis(tag, name, value):
@with_sigalrm_timeout(1) @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("&", "&amp;").replace('<','&lt;').replace('>','&gt;').replace('"', '&quot;').replace("'", "&#039;").strip() title = title.replace('','').replace('','').replace("\ufeff", "").replace("𒐪","").replace("\n", "").replace("\r", "").replace("\t", "").replace("&", "&amp;").replace('<','&lt;').replace('>','&gt;').replace('"', '&quot;').replace("'", "&#039;").strip()

View File

@ -332,16 +332,15 @@ def comment(v):
with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f: with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f:
f.write('\n{[para]}\n' + body) 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 body_for_sanitize = body
if v.owoify: if v.owoify:
body_for_sanitize = owoify(body_for_sanitize) body_for_sanitize = owoify(body_for_sanitize)
if v.marsify: if v.marsify:
body_for_sanitize = marsify(body_for_sanitize) 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(): 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: elif v.bird and len(body) > 140:
return {"error":"You have to type less than 140 characters!"}, 403 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): for i in poll_regex.finditer(body):
body = body.replace(i.group(0), "") body = body.replace(i.group(0), "")
option = CommentOption( option = CommentOption(
@ -772,7 +768,9 @@ def edit_comment(cid, v):
if v.marsify: if v.marsify:
body_for_sanitize = marsify(body_for_sanitize) 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) if len(body_html) > 20000: abort(400)

View File

@ -405,10 +405,9 @@ def edit_post(pid, v):
return {"error":"You have to type less than 140 characters!"}, 403 return {"error":"You have to type less than 140 characters!"}, 403
if title != p.title: if title != p.title:
if v.id == p.author_id and v.agendaposter and not v.marseyawarded and p.sub != 'chudrama': torture = (v.agendaposter and not v.marseyawarded and p.sub != 'chudrama' and v.id == p.author_id)
title = torture_ap(title, v.username)
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): 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 return {"error":"You can only type marseys!"}, 403
@ -421,9 +420,6 @@ def edit_post(pid, v):
body = body.strip() body = body.strip()
if body != p.body: 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): for i in poll_regex.finditer(body):
body = body.replace(i.group(0), "") body = body.replace(i.group(0), "")
option = SubmissionOption( option = SubmissionOption(
@ -443,7 +439,9 @@ def edit_post(pid, v):
g.db.add(option) 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): if v.id == p.author_id and v.marseyawarded and marseyaward_body_regex.search(body_html):
return {"error":"You can only type marseys!"}, 403 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.is_suspended: return error("You can't perform this action while banned.")
if v.agendaposter and not v.marseyawarded and sub != 'chudrama': torture = (v.agendaposter and not v.marseyawarded and sub != 'chudrama')
title = torture_ap(title, v.username)
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): if v.marseyawarded and not marseyaward_title_regex.fullmatch(title_html):
return error("You can only type marseys!") return error("You can only type marseys!")
@ -892,14 +889,13 @@ def submit_post(v, sub=None):
choices.append(i.group(1)) choices.append(i.group(1))
body = body.replace(i.group(0), "") 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 += process_files()
body = body.strip() 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): if v.marseyawarded and marseyaward_body_regex.search(body_html):
return error("You can only type marseys!") return error("You can only type marseys!")