From 8b5bf42b540199f41df8e856c3eae1301c0ef7c0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sun, 30 Jul 2023 09:16:01 +0300 Subject: [PATCH] fix snappy dupe detection --- files/routes/comments.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index de94cd506..0bbff8247 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -228,11 +228,14 @@ def comment(v): else: abort(415) - body = body.replace('\n ', '\n') - body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT] + body = body.replace('\n ', '\n').replace('\r', '') + body = body.strip()[:COMMENT_BODY_LENGTH_LIMIT].strip() - if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and posting_to_post and post_target.id == SNAPPY_THREAD and level == 1 and body not in SNAPPY_QUOTES: - with open(f"snappy_{SITE_NAME}.txt", "a", encoding="utf-8") as f: + if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and posting_to_post and post_target.id == SNAPPY_THREAD and level == 1: + with open(f"snappy_{SITE_NAME}.txt", "r+", encoding="utf-8") as f: + body_for_checking = '\n{[para]}\n' + body + '\n{[para]}\n' + if body_for_checking in f.read(): + abort(400, "Snappy quote already exists!") f.write('\n{[para]}\n' + body) body_for_sanitize = body