From 95239be4009b47816226c9fd7f87619da7a99fb5 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 15 Sep 2023 02:17:47 +0300 Subject: [PATCH] remove last snappy quote if author deletes their comment adding it --- files/routes/comments.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/files/routes/comments.py b/files/routes/comments.py index 704cf8395..ac53c17b5 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -450,6 +450,16 @@ def delete_comment(cid, v): for sort in COMMENT_SORTS.keys(): cache.delete(f'post_{c.parent_post}_{sort}') + if v.admin_level >= PERMS['USE_ADMIGGER_THREADS'] and c.parent_post == SNAPPY_THREAD and c.level == 1: + body = '\n{[para]}\n' + c.body + '\n' + with open(f"snappy_{SITE_NAME}.txt", "r", encoding="utf-8") as f: + old_text = f.read() + + if old_text.endswith(body): + new_text = old_text.split(body)[0] + '\n' + with open(f"snappy_{SITE_NAME}.txt", "w", encoding="utf-8") as f: + f.write(new_text) + return {"message": "Comment deleted!"} @app.post("/undelete/comment/")