From 0f58d70cce4a9a9412881e84583cee8c488f7c4f Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 19 Jan 2022 08:20:05 +0200 Subject: [PATCH] 100000000k --- files/classes/submission.py | 2 +- files/helpers/const.py | 2 +- files/helpers/sanitize.py | 10 ++- files/routes/awards.py | 8 +- files/routes/comments.py | 4 +- files/routes/login.py | 6 +- files/routes/posts.py | 2 +- files/routes/settings.py | 2 +- files/routes/users.py | 7 +- files/templates/comments.html | 4 +- files/templates/leaderboard.html | 102 +++++++++++++------------- files/templates/notifications.html | 2 +- files/templates/settings_profile.html | 2 +- files/templates/userpage.html | 4 +- 14 files changed, 81 insertions(+), 76 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 4326a55e1..69194a730 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -247,7 +247,7 @@ class Submission(Base): @property @lazy def full_url(self): - if self.url.startswith('/'): return f'https://{site}' + self.url + if self.url and self.url.startswith('/'): return f'https://{site}' + self.url return self.url @property diff --git a/files/helpers/const.py b/files/helpers/const.py index 6048a84f1..5dc9db6e9 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -702,7 +702,7 @@ AWARDS = { "grass": { "kind": "grass", "title": "Grass", - "description": "Ban the recipient permanently (must provide a timestamped picture of them touching grass to the admins to get unbanned)", + "description": "Ban the recipient for 30 days (if they provide a timestamped picture of them touching grass/snow/sand/ass to the admins, they will get unbanned immediately)", "icon": "fas fa-seedling", "color": "text-success", "price": 10000 diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index b9683cf08..993b23fcf 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -100,7 +100,7 @@ allowed_protocols = ['http', 'https'] allowed_styles = ['color', 'background-color', 'font-weight', 'transform', '-webkit-transform'] -def sanitize(sanitized, noimages=False, alert=False, comment=False): +def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = markdown(sanitized) @@ -202,7 +202,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False): classes = 'emoji-md' remoji = emoji - if random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) @@ -216,14 +216,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False): if emoji.startswith("!"): emoji = emoji[1:] classes = 'emoji mirrored' - if random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): sanitized = re.sub(f'(?', sanitized, flags=re.I) if comment: marseys_used.add(emoji) elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): classes = 'emoji' - if random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' sanitized = re.sub(f'(?', sanitized, flags=re.I) if comment: marseys_used.add(emoji) @@ -266,6 +266,8 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False): return sanitized + + def filter_emojis_only(title): title = title.replace('<','').replace('>','').replace("\n", "").replace("\r", "").replace("\t", "").strip() diff --git a/files/routes/awards.py b/files/routes/awards.py index f679de7a2..56dad3372 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -372,9 +372,11 @@ def award_post(pid, v): g.db.add(post.author) g.db.commit() - if request.referrer and len(request.referrer) > 1 and (request.referrer.startswith('/') or request.referrer.startswith(request.host_url)): - return redirect(request.referrer) - else: return redirect("/") + if request.referrer and len(request.referrer) > 1: + if request.referrer == f'{request.host_url}submit': return redirect(post.permalink) + elif request.referrer.startswith('/') or request.referrer.startswith(request.host_url): + return redirect(request.referrer) + return redirect("/") @app.get("/comment//awards") diff --git a/files/routes/comments.py b/files/routes/comments.py index 0a5f6fc6d..5735e537c 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -581,7 +581,7 @@ def edit_comment(cid, v): ) g.db.add(c_option) - body_html = sanitize(body) + body_html = sanitize(body, edit=True) if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))): return {"error":"You can only type marseys!"}, 403 @@ -656,7 +656,7 @@ def edit_comment(cid, v): body += f"\n\n{url}" else: return {"error": "Image/Video files only"}, 400 - body_html = sanitize(body) + body_html = sanitize(body, edit=True) if len(body_html) > 20000: abort(400) diff --git a/files/routes/login.py b/files/routes/login.py index ff479a9ec..352654661 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -300,13 +300,13 @@ def sign_up_post(v): ref_user = g.db.query(User).filter_by(id=ref_id).one_or_none() if ref_user: - if ref_user.referral_count: + if ref_user.referral_count and not ref_user.has_badge(10): new_badge = Badge(user_id=ref_user.id, badge_id=10) g.db.add(new_badge) - if ref_user.referral_count > 9: + if ref_user.referral_count > 9 and not ref_user.has_badge(11): new_badge = Badge(user_id=ref_user.id, badge_id=11) g.db.add(new_badge) - if ref_user.referral_count > 99: + if ref_user.referral_count > 99 and not ref_user.has_badge(12): new_badge = Badge(user_id=ref_user.id, badge_id=12) g.db.add(new_badge) diff --git a/files/routes/posts.py b/files/routes/posts.py index bf444bebb..4887c2e85 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -453,7 +453,7 @@ def edit_post(pid, v): ) g.db.add(c) - body_html = sanitize(body) + body_html = sanitize(body, edit=True) bans = filter_comment_html(body_html) if bans: diff --git a/files/routes/settings.py b/files/routes/settings.py index f2642f5aa..1710510e7 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -331,7 +331,7 @@ def settings_profile_post(v): theme = request.values.get("theme") if theme: - if theme in ["classic","transparent", "win98", "dark", "light", "coffee", "tron", "4chan", "midnight"]: + if theme in ["drambler","classic","transparent", "win98", "dark", "light", "coffee", "tron", "4chan", "midnight"]: if theme == "transparent" and not v.background: return {"error": "You need to set a background to use the transparent theme!"} v.theme = theme diff --git a/files/routes/users.py b/files/routes/users.py index bd6f028f7..964964077 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -91,7 +91,6 @@ def leaderboard_thread(): db.close() -gevent.spawn(leaderboard_thread()) @app.get("/grassed") @auth_required def grassed(v): @@ -350,6 +349,8 @@ def transfer_bux(v, username): @app.get("/leaderboard") @auth_required def leaderboard(v): + gevent.spawn(leaderboard_thread()) + sq = g.db.query(User.id, func.rank().over(order_by=User.coins.desc()).label("rank")).subquery() pos1 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] @@ -472,7 +473,7 @@ def message2(v, username): if v.shadowbanned: return {"message": "Message sent!"} - message = request.values.get("message", "").strip()[:1000].strip() + message = request.values.get("message", "").strip()[:10000].strip() if not message: return {"error": "message is empty"} @@ -540,7 +541,7 @@ def message2(v, username): @auth_required def messagereply(v): - message = request.values.get("body", "").strip()[:1000].strip() + message = request.values.get("body", "").strip()[:10000].strip() if not message: return {"error": "message is empty"} diff --git a/files/templates/comments.html b/files/templates/comments.html index 047067c6d..9dc29a36e 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -207,7 +207,7 @@ {% endif %} {% if c.distinguish_level %}{% endif %} - {% if c.is_op %}{% endif %} + {% if c.is_op and c.author_name != '👻' %}{% endif %} {% if c.is_bot %}{% endif %} {% if c.is_blocking %}{% endif %} {% if c.is_blocked %}{% endif %} @@ -541,7 +541,7 @@