From 07f2c0d2cae46ab0df64e0817599093747b39624 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 13 Jun 2022 20:05:24 +0200 Subject: [PATCH] make marsey counter work everywhere (not just comments) --- files/helpers/sanitize.py | 15 +++++++++++---- files/routes/comments.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 5dc55c5a8..c236bd7ec 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -124,7 +124,7 @@ def handler(signum, frame): print("Timeout!", flush=True) raise Exception("Timeout") -def render_emoji(html, regexp, edit, marseys_used=set(), b=False): +def render_emoji(html, regexp, edit, marseys_used, b=False): emojis = list(regexp.finditer(html)) captured = set() @@ -162,7 +162,7 @@ def render_emoji(html, regexp, edit, marseys_used=set(), b=False): return html -def sanitize(sanitized, alert=False, comment=False, edit=False): +def sanitize(sanitized, alert=False, edit=False): signal.signal(signal.SIGALRM, handler) signal.alarm(1) @@ -269,7 +269,7 @@ def sanitize(sanitized, alert=False, comment=False, edit=False): sanitized = video_sub_regex.sub(r'\1', sanitized) sanitized = audio_sub_regex.sub(r'\1', sanitized) - if comment: + if not edit: for marsey in g.db.query(Marsey).filter(Marsey.name.in_(marseys_used)).all(): marsey.count += 1 g.db.add(marsey) @@ -364,7 +364,14 @@ def filter_emojis_only(title, edit=False, graceful=False): title = title.replace('‎','').replace('​','').replace("\ufeff", "").replace("𒐪","").replace("\n", "").replace("\r", "").replace("\t", "").replace("&", "&").replace('<','<').replace('>','>').replace('"', '"').replace("'", "'").strip() - title = render_emoji(title, emoji_regex3, edit) + marseys_used = set() + + title = render_emoji(title, emoji_regex3, edit, marseys_used) + + if not edit: + for marsey in g.db.query(Marsey).filter(Marsey.name.in_(marseys_used)).all(): + marsey.count += 1 + g.db.add(marsey) title = strikethrough_regex.sub(r'\1', title) diff --git a/files/routes/comments.py b/files/routes/comments.py index 2f5bbdd0c..b84324895 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -325,7 +325,7 @@ def api_comment(v): if v.agendaposter and not v.marseyawarded and parent_post.id not in ADMIGGERS: body = torture_ap(body, v.username) - body_html = sanitize(body, comment=True) + body_html = sanitize(body) if parent_post.id not in ADMIGGERS and '!slots' not in body.lower() and '!blackjack' not in body.lower() and '!wordle' not in body.lower() and AGENDAPOSTER_PHRASE not in body.lower():