From 0233c58a2eab4c4b53da7e938a839d432fe7063a Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 21 Jan 2022 22:56:56 +0200 Subject: [PATCH] cxvxcv --- files/classes/submission.py | 8 ++++++- files/helpers/sanitize.py | 25 +++++++++++++--------- files/routes/feeds.py | 4 ++-- files/routes/posts.py | 2 +- files/routes/votes.py | 5 ++--- files/templates/submission.html | 28 ++++++++++++++----------- files/templates/submission_listing.html | 22 +++++++++++-------- 7 files changed, 56 insertions(+), 38 deletions(-) diff --git a/files/classes/submission.py b/files/classes/submission.py index 64f18bdc4..258805f08 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -219,6 +219,12 @@ class Submission(Base): if domain.startswith("www."): domain = domain.split("www.")[1] return domain.replace("old.reddit.com", "reddit.com") + @property + @lazy + def author_name(self): + if self.award_count('ghosts'): return '👻' + else: return self.author.username + @property @lazy def is_youtube(self): @@ -251,7 +257,7 @@ class Submission(Base): flags = {} for f in self.flags: flags[f.user.username] = f.reason - data = {'author_name': self.author.username if self.author else '', + data = {'author_name': self.author_name if self.author else '', 'permalink': self.permalink, 'is_banned': bool(self.is_banned), 'deleted_utc': self.deleted_utc, diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index a2868ccb6..12c1cecc4 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -181,7 +181,9 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read()) marseys_used = set() - for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized): + emojis = re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized) + if len(list(emojis)) > 20: edit = True + for i in emojis: old = i.group(0) if 'marseylong1' in old or 'marseylong2' in old or 'marseyllama1' in old or 'marseyllama2' in old: new = old.lower().replace(">", " class='mb-0'>") else: new = old.lower() @@ -200,7 +202,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): classes = 'emoji-md' remoji = emoji - if not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): new = re.sub(f'(?', new, flags=re.I) @@ -208,20 +210,21 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = sanitized.replace(old, new) - - for i in re.finditer('(? 20: edit = True + for i in emojis: emoji = i.group(1).lower() if emoji.startswith("!"): emoji = emoji[1:] classes = 'emoji mirrored' - if not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.005 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 not edit and random() < 0.01 and 'marsey' in emoji: classes += ' golden' + if not edit and random() < 0.005 and 'marsey' in emoji: classes += ' golden' sanitized = re.sub(f'(?', sanitized, flags=re.I) if comment: marseys_used.add(emoji) @@ -266,25 +269,27 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): -def filter_emojis_only(title): +def filter_emojis_only(title, edit=False): title = title.replace('<','').replace("\n", "").replace("\r", "").replace("\t", "").strip() title = bleach.clean(title, tags=[]) - for i in re.finditer('(? 20: edit = True + for i in emojis: emoji = i.group(1).lower() 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.005 and 'marsey' in emoji: classes += ' golden' if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): title = re.sub(f'(?', title, flags=re.I) 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.005 and 'marsey' in emoji: classes += ' golden' title = re.sub(f'(?', title, flags=re.I) if len(title) > 1500: abort(400) diff --git a/files/routes/feeds.py b/files/routes/feeds.py index 06e7e2592..398bbf028 100644 --- a/files/routes/feeds.py +++ b/files/routes/feeds.py @@ -51,9 +51,9 @@ def feeds_user(v=None, sort='hot', t='all'): with tag("author"): with tag("name"): - text(post.author.username) + text(post.author_name) with tag("uri"): - text(f'{request.host_url}@{post.author.username}') + text(f'{request.host_url}@{post.author_name}') doc.stag("link", href=full_link(post.permalink)) diff --git a/files/routes/posts.py b/files/routes/posts.py index ae4e3e49e..c4d824e5a 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -411,7 +411,7 @@ def edit_post(pid, v): if title != p.title: if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username) - title_html = filter_emojis_only(title) + title_html = filter_emojis_only(title, edit=True) if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html))): return {"error":"You can only type marseys!"}, 403 p.title = title[:500] p.title_html = title_html diff --git a/files/routes/votes.py b/files/routes/votes.py index d2396b0ac..7f2d2aa6d 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -22,8 +22,9 @@ def admin_vote_info_get(v): else: abort(400) except: abort(400) - if isinstance(thing, Submission): + if thing.author_name == '👻': abort(403) + if isinstance(thing, Submission): if thing.author.shadowbanned and not (v and v.admin_level): thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0] else: thing_id = thing.id @@ -39,8 +40,6 @@ def admin_vote_info_get(v): ).order_by(Vote.id).all() elif isinstance(thing, Comment): - if thing.author_name == '👻': abort(403) - if thing.author.shadowbanned and not (v and v.admin_level): thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0] else: thing_id = thing.id diff --git a/files/templates/submission.html b/files/templates/submission.html index 55ccb2723..4ec3b2c25 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -161,11 +161,11 @@ {{p.plaintitle(v)}} - {{SITE_NAME}} -{% if p.author %}{% endif %} +{% if p.author %}{% endif %} {% if p.edited_utc %}{% endif %} -{% if p.author %}{% endif %} +{% if p.author %}{% endif %} {% if p.url and p.is_video %} @@ -177,7 +177,7 @@ -{% if p.author %}{% endif %} +{% if p.author %}{% endif %} @@ -201,7 +201,7 @@