From 8a0d51c4e01b405fcb8987de37a3def0608a8bb3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 7 Jan 2022 21:13:01 +0200 Subject: [PATCH] cvxx --- files/helpers/alerts.py | 16 +++++++-- files/helpers/markdown.py | 3 ++ files/routes/awards.py | 4 ++- files/routes/posts.py | 22 +++++++------ files/routes/static.py | 4 +-- files/templates/comments.html | 2 +- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- snappy_Drama.txt | 44 +++++++++++++++++++++++++ 9 files changed, 80 insertions(+), 19 deletions(-) diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index 01110ef1c..54b63d0f7 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -104,8 +104,18 @@ def NOTIFY_USERS(text, v): soup = BeautifulSoup(text, features="html.parser") for mention in soup.find_all("a", href=re.compile("^\/id\/([0-9]+)")): id = int(mention["href"].split("/id/")[1]) - if id != v.id: - user = g.db.query(User).filter_by(id=id).one_or_none() - if user and not v.any_block_exists(user): notify_users.add(user.id) + if id != v.id: notify_users.add(id) + + return notify_users + +def NOTIFY_USERS2(text, v): + notify_users = set() + for word, id in NOTIFIED_USERS.items(): + if id == 0: continue + if word in text.lower() and id not in notify_users and v.id != id: notify_users.add(id) + + for i in re.finditer("(^|\s|\n)@((\w|-){1,25})", text): + user = get_user(i.group(2), graceful=True) + if user and not v.any_block_exists(user): notify_users.add(user.id) return notify_users \ No newline at end of file diff --git a/files/helpers/markdown.py b/files/helpers/markdown.py index 7b5118c9b..eb0aa0be5 100644 --- a/files/helpers/markdown.py +++ b/files/helpers/markdown.py @@ -39,6 +39,7 @@ class CustomRenderer(HTMLRenderer): user = get_user(target, graceful=True) + if g.v.admin_level == 0 and g.v.any_block_exists(user): return f"{space}@{target}" if not user: return f"{space}@{target}" @@ -67,6 +68,8 @@ class Renderer(HTMLRenderer): user = get_user(target, graceful=True) + if g.v.admin_level == 0 and g.v.any_block_exists(user): return f"{space}@{target}" + if not user: return f"{space}@{target}" return f'{space}@{user.username}' diff --git a/files/routes/awards.py b/files/routes/awards.py index 0f7461759..764eafc45 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -600,8 +600,10 @@ def admin_userawards_post(v): note = "" for key, value in notify_awards.items(): - note += f"{value} {AWARDS[key]['title']} {'Awards' if value != 1 else 'Award'}, " + note += f"{value} {AWARDS[key]['title']}, " + if len(note) > 256: return {"error": "You're giving too many awards at the same time!"} + ma=ModAction( kind="grant_awards", user_id=v.id, diff --git a/files/routes/posts.py b/files/routes/posts.py index 74390d92d..6bbdc5e2b 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -15,7 +15,7 @@ from io import BytesIO from files.__main__ import app, limiter, cache, db_session from PIL import Image as PILimage from .front import frontlist, changeloglist -from urllib.parse import ParseResult, urlunparse, urlparse, quote +from urllib.parse import ParseResult, urlunparse, urlparse, quote, unquote from os import path import requests from shutil import copyfile @@ -57,7 +57,7 @@ def publish(pid, v): post.created_utc = int(time.time()) g.db.add(post) - notify_users = NOTIFY_USERS(f'{post.body_html}{post.title}', v) + notify_users = NOTIFY_USERS(post.body_html, v) | NOTIFY_USERS2(post.title, v) cid = notif_comment(f"@{v.username} has mentioned you: [{post.title}]({post.permalink})") for x in notify_users: @@ -526,7 +526,7 @@ def edit_post(pid, v): g.db.add(n) - notify_users = NOTIFY_USERS(f'{body_html}{title}', v) + notify_users = NOTIFY_USERS(body_html, v) | NOTIFY_USERS2(title, v) soup = BeautifulSoup(body_html, features="html.parser") @@ -745,13 +745,14 @@ def submit_post(v): url = urlunparse(new_url) - repost = g.db.query(Submission).filter( - Submission.url.ilike(url), - Submission.deleted_utc == 0, - Submission.is_banned == False - ).one_or_none() + if SITE != 'localhost': + repost = g.db.query(Submission).filter( + Submission.url.ilike(url), + Submission.deleted_utc == 0, + Submission.is_banned == False + ).one_or_none() - if repost: return redirect(repost.permalink) + if repost: return redirect(repost.permalink) domain_obj = get_domain(domain) if domain_obj: @@ -763,6 +764,7 @@ def submit_post(v): try: embed = requests.get("https://publish.twitter.com/oembed", timeout=5, params={"url":url, "omit_script":"t"}).json()["html"] except: embed = None elif url.startswith('https://youtube.com/watch?v='): + url = unquote(url).replace('?t', '&t') yt_id = url.split('https://youtube.com/watch?v=')[1].split('&')[0].split('%')[0] params = parse_qs(urlparse(url).query) t = params.get('t', params.get('start', [0]))[0] @@ -1018,7 +1020,7 @@ def submit_post(v): if not new_post.private: - notify_users = NOTIFY_USERS(f'{body_html}{title}', v) + notify_users = NOTIFY_USERS(body_html, v) | NOTIFY_USERS2(title, v) cid = notif_comment(f"@{v.username} has mentioned you: [{title}]({new_post.permalink})") for x in notify_users: diff --git a/files/routes/static.py b/files/routes/static.py index 9d042672a..57e30f9e3 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -103,10 +103,10 @@ def cached_chart(days): if days > 31: file = "/weekly_chart.png" - day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(30)][1:] + day_cutoffs = [today_cutoff - 86400 * 7 * i for i in range(35)][1:] else: file = "/daily_chart.png" - day_cutoffs = [today_cutoff - 86400 * i for i in range(30)][1:] + day_cutoffs = [today_cutoff - 86400 * i for i in range(35)][1:] day_cutoffs.insert(0, calendar.timegm(now)) diff --git a/files/templates/comments.html b/files/templates/comments.html index e0ec73171..fc639ed1f 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -193,7 +193,7 @@ {% endif %} {% if c.bannedfor %} - + {% endif %} {% if c.active_flags %}{{c.active_flags}} Reports{% endif %} {% if c.over_18 %}+18{% endif %} diff --git a/files/templates/submission.html b/files/templates/submission.html index 82d104c62..662e7c365 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -329,7 +329,7 @@
{% if p.bannedfor %} - + {% endif %} {% if p.awards %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index a916f0455..5880b41b9 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -167,7 +167,7 @@