From c9a0e91e24d226e1d5d2955f74c2df0869eb8107 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 21 Oct 2021 22:50:00 +0200 Subject: [PATCH] flairlock --- files/classes/user.py | 2 +- files/helpers/const.py | 10 ++++++- files/helpers/sanitize.py | 22 ++++++++++++++++ files/helpers/wrappers.py | 6 ----- files/routes/admin.py | 2 +- files/routes/awards.py | 35 ++++++++++++++++++++++--- files/routes/comments.py | 2 +- files/routes/posts.py | 23 ---------------- files/routes/settings.py | 2 +- files/routes/votes.py | 14 ++++++++++ files/templates/award_modal.html | 12 ++++----- files/templates/comments.html | 12 ++++++++- files/templates/submission_listing.html | 2 +- schema.sql | 2 +- 14 files changed, 100 insertions(+), 46 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 89168eecd..80552d217 100755 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -71,7 +71,7 @@ class User(Base): hidevotedon = Column(Boolean, default=False) highlightcomments = Column(Boolean, default=True) slurreplacer = Column(Boolean, default=True) - flairchanged = Column(Boolean, default=False) + flairchanged = Column(Integer) newtab = Column(Boolean, default=False) newtabexternal = Column(Boolean, default=True) oldreddit = Column(Boolean, default=True) diff --git a/files/helpers/const.py b/files/helpers/const.py index d11ce4733..afd14f7d6 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -196,11 +196,19 @@ if SITE_NAME == "Drama": "agendaposter": { "kind": "agendaposter", "title": "Agendaposter", - "description": "Force the agendaposter theme on the author for 24 hours.", + "description": "Forces the agendaposter theme on the author for 24 hours.", "icon": "fas fa-snooze", "color": "text-purple", "price": 2000 }, + "flairlock": { + "kind": "flairlock", + "title": "!-Day Flairlock", + "description": "Sets a flair for the author and locks it or 24 hours.", + "icon": "fas fa-lock", + "color": "text-black", + "price": 1250 + }, } else: AWARDS = { diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 50741bc3a..05122b70c 100755 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -227,3 +227,25 @@ def sanitize(sanitized, noimages=False): sanitized = re.sub('

(https:\/\/[^ <>]*)', r'

\1

', sanitized) return sanitized + +def filter_title(title): + title = title.strip() + title = title.replace("\n", "") + title = title.replace("\r", "") + title = title.replace("\t", "") + + title = bleach.clean(title, tags=[]) + + for i in re.finditer('(?', title) + + elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): + title = re.sub(f'(?', title) + + if len(title) > 1500: abort(400) + else: return title \ No newline at end of file diff --git a/files/helpers/wrappers.py b/files/helpers/wrappers.py index f1780960c..94f489b55 100755 --- a/files/helpers/wrappers.py +++ b/files/helpers/wrappers.py @@ -24,12 +24,6 @@ def get_logged_in_user(): else: v = None except: v = None - if v and v.agendaposter_expires_utc and v.agendaposter_expires_utc < g.timestamp: - v.agendaposter_expires_utc = 0 - v.agendaposter = False - - g.db.add(v) - if v and (nonce < v.login_nonce): x= (None, None) else: diff --git a/files/routes/admin.py b/files/routes/admin.py index 17be88496..f29a7684e 100755 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -806,7 +806,7 @@ def admin_title_change(user_id, v): user=g.db.query(User).with_for_update().options(lazyload('*')).filter_by(id=user.id).first() user.customtitle=new_name - user.flairchanged = bool(request.values.get("locked")) + if request.values.get("locked"): user.flairchanged = time.time() + 2629746 g.db.add(user) if user.flairchanged: kind = "set_flair_locked" diff --git a/files/routes/awards.py b/files/routes/awards.py index eaf066894..a26626149 100755 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -6,6 +6,7 @@ from files.helpers.const import * from files.classes.award import * from .front import frontlist from flask import g, request +from files.helpers.sanitize import filter_title AWARDS2 = { "ban": { @@ -107,11 +108,19 @@ def shop(v): "agendaposter": { "kind": "agendaposter", "title": "Agendaposter", - "description": "Force the agendaposter theme on the author for 24 hours.", + "description": "Forces the agendaposter theme on the author for 24 hours.", "icon": "fas fa-snooze", "color": "text-purple", "price": 2000 }, + "flairlock": { + "kind": "flairlock", + "title": "1-Day Flairlock", + "description": "Sets a flair for the author and locks it or 24 hours.", + "icon": "fas fa-lock", + "color": "text-black", + "price": 1250 + }, } else: AWARDS = { @@ -257,11 +266,19 @@ def buy(v, award): "agendaposter": { "kind": "agendaposter", "title": "Agendaposter", - "description": "Force the agendaposter theme on the author for 24 hours.", + "description": "Forces the agendaposter theme on the author for 24 hours.", "icon": "fas fa-snooze", "color": "text-purple", "price": 2000 }, + "flairlock": { + "kind": "flairlock", + "title": "1-Day Flairlock", + "description": "Sets a flair for the author and locks it or 24 hours.", + "icon": "fas fa-lock", + "color": "text-black", + "price": 1250 + }, } else: AWARDS = { @@ -428,6 +445,12 @@ def award_post(pid, v): if not author.has_badge(26): badge = Badge(user_id=author.id, badge_id=26) g.db.add(badge) + elif kind == "flairlock": + new_name = note[:100].replace("𒐪","") + author.customtitleplain = new_name + author.customtitle = filter_title(new_name) + if len(author.customtitle) > 1000: abort(403) + author.flairchanged = time.time() + 86400 post.author.received_award_count += 1 g.db.add(post.author) @@ -529,7 +552,13 @@ def award_comment(cid, v): if not author.has_badge(26): badge = Badge(user_id=author.id, badge_id=26) g.db.add(badge) - + elif kind == "flairlock": + new_name = note[:100].replace("𒐪","") + author.customtitleplain = new_name + author.customtitle = filter_title(new_name) + if len(author.customtitle) > 1000: abort(403) + author.flairchanged = time.time() + 86400 + c.author.received_award_count += 1 g.db.add(c.author) diff --git a/files/routes/comments.py b/files/routes/comments.py index e24365829..be00c9056 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -9,7 +9,7 @@ from files.routes.front import comment_idlist from pusher_push_notifications import PushNotifications from flask import * from files.__main__ import app, limiter -from .posts import filter_title +from files.helpers.sanitize import filter_title site = environ.get("DOMAIN").strip() diff --git a/files/routes/posts.py b/files/routes/posts.py index 5fe259418..cf73ce7cb 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -335,29 +335,6 @@ def archiveorg(url): try: requests.get(f'https://web.archive.org/save/{url}', headers={'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}, timeout=100) except Exception as e: print(e) -def filter_title(title): - title = title.strip() - title = title.replace("\n", "") - title = title.replace("\r", "") - title = title.replace("\t", "") - - title = bleach.clean(title, tags=[]) - - for i in re.finditer('(?', title) - - elif path.isfile(f'./files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title) - - if len(title) > 1500: abort(400) - else: return title - - def thumbnail_thread(pid): diff --git a/files/routes/settings.py b/files/routes/settings.py index d25534afd..c056f883f 100755 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -10,7 +10,7 @@ from files.__main__ import app, cache, limiter import youtube_dl from .front import frontlist import os -from .posts import filter_title +from files.helpers.sanitize import filter_title from files.helpers.discord import add_role from shutil import copyfile import requests diff --git a/files/routes/votes.py b/files/routes/votes.py index 704b28771..5f61b88c4 100755 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -101,6 +101,16 @@ def api_vote_post(post_id, new, v): post.stickied = None g.db.add(post) cache.delete_memoized(frontlist) + + if v.agendaposter_expires_utc and v.agendaposter_expires_utc < time.time(): + v.agendaposter_expires_utc = 0 + v.agendaposter = False + g.db.add(v) + + if v.flairchanged and v.flairchanged < time.time(): + v.flairchanged = None + g.db.add(v) + try: g.db.flush() post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() @@ -159,6 +169,10 @@ def api_vote_comment(comment_id, new, v): g.db.add(vote) + if comment.is_pinned and comment.is_pinned.startswith("t:") and int(time.time()) > int(comment.is_pinned[2:]): + comment.is_pinned = None + g.db.add(comment) + try: g.db.flush() comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index 75a415da3..827cc2e59 100755 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,4 +1,4 @@ - + @@ -76,7 +76,7 @@ @media (min-width: 767.98px) { .award-columns { - column-count: 9 !important; + column-count: 5 !important; } } \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index 1d99ca9ae..fab23eb12 100755 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -107,6 +107,16 @@ const date = new Date({{c.created_utc*1000}}); document.getElementById('timestamp-{{c.id}}').title = date.toString(); })() + + {% if c.is_pinned %} + const pinned_info = document.getElementById('pinned-{{c.id}}') + {% if c.is_pinned.startswith('t:') %} + pinned_info.setAttribute("data-bs-original-title", `Pinned until ${new Date({{c.is_pinned[2:]}} * 1000).toString()}`) + {% else %} + pinned_info.setAttribute("data-bs-original-title", "Pinned by @{{c.is_pinned}}") + {%endif%} + {%endif%} + })()