From 5f6eb77768f4f1d6d9840c0d2763d27b61e17c44 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 22 Nov 2021 16:16:58 +0200 Subject: [PATCH] fdsfddfs --- files/helpers/alerts.py | 6 ++++-- files/routes/admin.py | 6 ++---- files/routes/comments.py | 8 +++----- files/routes/posts.py | 6 ++---- files/routes/reporting.py | 8 ++++++-- files/routes/settings.py | 6 ++---- files/routes/users.py | 2 +- files/templates/userpage.html | 6 +++--- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 59210d7d8..2ffbbd948 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -11,15 +11,17 @@ def send_notification(uid, text, autojanny=False): text = text.replace('r/', 'r\/').replace('u/', 'u\/') text_html = CustomRenderer().render(mistletoe.Document(text)) - text_html = sanitize(text_html) if autojanny: author_id = AUTOJANNY_ID else: author_id = NOTIFICATIONS_ID + existing = g.db.query(Comment.id).filter(Comment.author_id == author_id, Comment.body_html == text_html, Comment.notifiedto == uid).first() + if existing: return + new_comment = Comment(author_id=author_id, parent_submission=None, - distinguish_level=6,body=text, + distinguish_level=6, body_html=text_html, notifiedto=uid ) diff --git a/files/routes/admin.py b/files/routes/admin.py index 2ee33ef7f..a0c5b4c4e 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -995,15 +995,13 @@ def api_sticky_post(post_id, v): if post.stickied: if v.id != post.author_id: message = f"@{v.username} has pinned your [post](/post/{post_id})!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first() - if not existing: send_notification(post.author_id, message) + send_notification(post.author_id, message) g.db.commit() return {"message": "Post pinned!"} else: if v.id != post.author_id: message = f"@{v.username} has unpinned your [post](/post/{post_id})!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first() - if not existing: send_notification(post.author_id, message) + send_notification(post.author_id, message) g.db.commit() return {"message": "Post unpinned!"} diff --git a/files/routes/comments.py b/files/routes/comments.py index 8ad018d39..396ddaa30 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -208,7 +208,7 @@ def api_comment(v): Comment.deleted_utc == 0, Comment.parent_comment_id == parent_comment_id, Comment.parent_submission == parent_submission, - Comment.body == body + Comment.body_html == body_html ).first() if existing: return {"error": f"You already made that comment: /comment/{existing.id}"}, 409 @@ -885,15 +885,13 @@ def toggle_pin_comment(cid, v): if comment.is_pinned: if v.id != comment.author_id: message = f"@{v.username} has pinned your [comment]({comment.permalink})!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first() - if not existing: send_notification(comment.author_id, message) + send_notification(comment.author_id, message) g.db.commit() return {"message": "Comment pinned!"} else: if v.id != comment.author_id: message = f"@{v.username} has unpinned your [comment]({comment.permalink})!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message).first() - if not existing: send_notification(comment.author_id, message) + send_notification(comment.author_id, message) g.db.commit() return {"message": "Comment unpinned!"} diff --git a/files/routes/posts.py b/files/routes/posts.py index cbe3161c4..97a02445d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -350,9 +350,7 @@ def edit_post(pid, v): notify_users.add(541) if ('idio3' in f'{body_html}{title}'.lower() or 'idio ' in f'{body_html}{title}'.lower()) and 30 not in notify_users: notify_users.add(30) - for x in notify_users: - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first() - if not existing: send_notification(x, message) + for x in notify_users: send_notification(x, message) if (title != p.title or body != p.body) and v.id == p.author_id: @@ -544,7 +542,7 @@ def submit_post(v): url = url.replace("old.reddit.com/gallery", "new.reddit.com/gallery") url = url.replace("https://mobile.twitter.com", "https://twitter.com").replace("https://m.facebook", "https://facebook").replace("https://m.wikipedia", "https://wikipedia").replace("https://m.youtube", "https://youtube") - + if url.startswith("https://streamable.com/") and not url.startswith("https://streamable.com/e/"): url = url.replace("https://streamable.com/", "https://streamable.com/e/") parsed_url = urlparse(url) diff --git a/files/routes/reporting.py b/files/routes/reporting.py index d7c9be5af..4e8cde187 100644 --- a/files/routes/reporting.py +++ b/files/routes/reporting.py @@ -21,7 +21,9 @@ def api_flag_post(pid, v): for i in re.finditer(':(.{1,30}?):', reason): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'): - reason = reason.replace(f':{i.group(1)}:', f'') + reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') + + if len(reason) > 350: return {"error": f"Too long."} flag = Flag(post_id=post.id, user_id=v.id, @@ -53,7 +55,9 @@ def api_flag_comment(cid, v): for i in re.finditer(':(.{1,30}?):', reason): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.webp'): - reason = reason.replace(f':{i.group(1)}:', f'') + reason = reason.replace(f':{i.group(1)}:', f':{i.group(1)}:') + + if len(reason) > 350: return {"error": f"Too long."} flag = CommentFlag(comment_id=comment.id, user_id=v.id, diff --git a/files/routes/settings.py b/files/routes/settings.py index f9ca65663..317059a94 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -244,8 +244,7 @@ def settings_profile_post(v): for x in notify_users: message = f"@{v.username} has added you to their friends list!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first() - if not existing: send_notification(x, message) + send_notification(x, message) v.friends = friends[:500] v.friends_html=friends_html @@ -289,8 +288,7 @@ def settings_profile_post(v): for x in notify_users: message = f"@{v.username} has added you to their enemies list!" - existing = g.db.query(Comment.id).filter(Comment.author_id == NOTIFICATIONS_ID, Comment.body == message, Comment.notifiedto == x).first() - if not existing: send_notification(x, message) + send_notification(x, message) v.enemies = enemies[:500] v.enemies_html=enemies_html diff --git a/files/routes/users.py b/files/routes/users.py index 0142226b1..b28aa5d97 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -848,7 +848,7 @@ def fp(v, fp): new_alt = Alt(user1=v.id, user2=u.id) g.db.add(new_alt) g.db.flush() - print(v.username + ' + ' + u.username) + print('\n\n' + v.username + ' + ' + u.username + '\n\n') g.db.add(v) g.db.commit() return '' \ No newline at end of file diff --git a/files/templates/userpage.html b/files/templates/userpage.html index 68d5d8ef3..150ccaf77 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -293,7 +293,7 @@ Profile views {% endif %} - {% if v and v.mute and not u.unmutable %} + {% if u.song and v and v.mute and not u.unmutable %} Pause anthem Play anthem {% endif %} @@ -425,7 +425,7 @@ {% endblock %} {% block mobileUserBanner %} -
+
@@ -525,7 +525,7 @@ Profile views {% endif %} - {% if v and v.mute and not u.unmutable %} + {% if u.song and v and v.mute and not u.unmutable %} Pause anthem Play anthem {% endif %}