From 14c7148eed64d568aa2ef6b2e323f8184995faae Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 24 Feb 2022 10:28:13 +0200 Subject: [PATCH] fd --- files/classes/comment.py | 6 ++-- files/classes/submission.py | 6 ++-- files/classes/user.py | 4 +-- files/helpers/alerts.py | 4 +-- files/helpers/const.py | 8 ++--- files/helpers/filters.py | 4 +-- files/helpers/get.py | 6 ---- files/helpers/sanitize.py | 41 ++++++++++++++++-------- files/routes/comments.py | 28 ++++++++-------- files/routes/front.py | 2 -- files/routes/login.py | 4 +-- files/routes/posts.py | 55 +++++++++++++++----------------- files/routes/search.py | 4 +-- files/routes/settings.py | 20 ++++++------ files/routes/static.py | 3 -- files/routes/subs.py | 8 ++--- files/routes/users.py | 5 --- files/templates/emoji_modal.html | 2 +- files/templates/marseys.html | 4 +-- files/templates/submission.html | 2 ++ 20 files changed, 105 insertions(+), 111 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index d06c06bc6..4ef281954 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -85,12 +85,12 @@ class Comment(Base): @property @lazy def options(self): - return tuple(x for x in self.child_comments if x.author_id == AUTOPOLLER_ID) + return [x for x in self.child_comments if x.author_id == AUTOPOLLER_ID] @property @lazy def choices(self): - return tuple(x for x in self.child_comments if x.author_id == AUTOCHOICE_ID) + return [x for x in self.child_comments if x.author_id == AUTOCHOICE_ID] def total_poll_voted(self, v): if v: @@ -100,7 +100,7 @@ class Comment(Base): def total_choice_voted(self, v): if v: - return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_(tuple(x.id for x in self.choices))).all() + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all() return False @property diff --git a/files/classes/submission.py b/files/classes/submission.py index 597878e78..760dc4181 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -107,7 +107,7 @@ class Submission(Base): def total_choice_voted(self, v): if v and self.choices: - return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_(tuple(x.id for x in self.choices))).all() + return g.db.query(CommentVote).filter(CommentVote.user_id == v.id, CommentVote.comment_id.in_([x.id for x in self.choices])).all() return False def total_bet_voted(self, v): @@ -221,8 +221,8 @@ class Submission(Base): if self.club: return link output = self.title.lower() - output = re.sub('&\w{2,3};', '', output, re.A) - output = [re.sub('\W', '', word, re.A) for word in output.split()] + output = re.sub('&\w{2,3};', '', output, flags=re.A) + output = [re.sub('\W', '', word, flags=re.A) for word in output.split()] output = [x for x in output if x][:6] output = '-'.join(output) if not output: output = '-' diff --git a/files/classes/user.py b/files/classes/user.py index 9de72f263..a841ce5cb 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -163,7 +163,7 @@ class User(Base): @property @lazy def all_blocks(self): - return tuple(x[0] for x in g.db.query(SubBlock.sub).filter_by(user_id=self.id).all()) + return [x[0] for x in g.db.query(SubBlock.sub).filter_by(user_id=self.id).all()] @lazy def blocks(self, sub): @@ -214,7 +214,7 @@ class User(Base): @property @lazy def paid_dues(self): - return self.admin_level or self.club_allowed or self.patron > 1 or (self.patron == 1 and self.truecoins > dues/10) or (self.club_allowed != False and self.truecoins > dues) + return self.admin_level or self.club_allowed or self.patron > 1 or (self.patron == 1 and self.truecoins > dues/5) or (self.club_allowed != False and self.truecoins > dues) @lazy def any_block_exists(self, other): diff --git a/files/helpers/alerts.py b/files/helpers/alerts.py index daa3fd543..f995b53f3 100644 --- a/files/helpers/alerts.py +++ b/files/helpers/alerts.py @@ -67,7 +67,7 @@ def NOTIFY_USERS(text, v): if id == 0: continue if word in text.lower() and id not in notify_users and v.id != id: notify_users.add(id) - soup = BeautifulSoup(text, 'html.parser') + soup = BeautifulSoup(text, 'lxml') for mention in soup.find_all("a", href=re.compile("^\/id\/([0-9]+)")): id = int(mention["href"].split("/id/")[1]) if id != v.id: @@ -82,7 +82,7 @@ def NOTIFY_USERS2(text, v): 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, re.A): + for i in re.finditer("(^|\s|\n)@((\w|-){1,25})", text, flags=re.A): user = get_user(i.group(2), graceful=True) if user and not v.any_block_exists(user): notify_users.add(user.id) diff --git a/files/helpers/const.py b/files/helpers/const.py index 4524fd9ac..28dad95f6 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -106,8 +106,8 @@ SLURS = { single_words = "|".join([slur.lower() for slur in SLURS.keys()]) -SLUR_REGEX = re.compile(rf"((?<=\s|>)|^)({single_words})((?=[\s<,.$]|s[\s<,.$]))", re.I|re.A) -SLUR_REGEX_UPPER = re.compile(rf"((?<=\s|>)|^)({single_words.upper()})((?=[\s<,.$]|S[\s<,.$]))", re.A) +SLUR_REGEX = re.compile(rf"((?<=\s|>)|^)({single_words})((?=[\s<,.$]|s[\s<,.$]))", flags=re.I|re.A) +SLUR_REGEX_UPPER = re.compile(rf"((?<=\s|>)|^)({single_words.upper()})((?=[\s<,.$]|S[\s<,.$]))", flags=re.A) def sub_matcher(match): return SLURS[match.group(0).lower()] @@ -125,8 +125,8 @@ def torture_ap(body, username): body = SLUR_REGEX_UPPER.sub(sub_matcher_upper, body) body = SLUR_REGEX.sub(sub_matcher, body) for k, l in AJ_REPLACEMENTS.items(): body = body.replace(k, l) - body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, re.I|re.A) - body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, re.I|re.A) + body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, flags=re.I|re.A) + body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, flags=re.I|re.A) return body diff --git a/files/helpers/filters.py b/files/helpers/filters.py index 0b9f70f12..f6d1ecff8 100644 --- a/files/helpers/filters.py +++ b/files/helpers/filters.py @@ -5,7 +5,7 @@ from files.classes import BannedDomain def filter_comment_html(html_text): - soup = BeautifulSoup(html_text, 'html.parser') + soup = BeautifulSoup(html_text, 'lxml') links = soup.find_all("a") @@ -28,7 +28,7 @@ def filter_comment_html(html_text): new_domain += "." + parts[j] domain_list.add(new_domain) - bans = tuple(x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(list(domain_list))).all()) + bans = [x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(list(domain_list))).all()] if bans: return bans else: return [] diff --git a/files/helpers/get.py b/files/helpers/get.py index 0d2fbed44..76f2140e3 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -140,8 +140,6 @@ def get_posts(pids, v=None): if not pids: return [] - pids=tuple(pids) - if v: vt = g.db.query(Vote).filter( Vote.submission_id.in_(pids), @@ -218,8 +216,6 @@ def get_comments(cids, v=None, load_parent=False): if not cids: return [] - cids=tuple(cids) - if v: votes = g.db.query(CommentVote).filter_by(user_id=v.id).subquery() @@ -282,8 +278,6 @@ def get_domain(s): domain_list.add(new_domain) - domain_list = tuple(list(domain_list)) - doms = [x for x in g.db.query(BannedDomain).filter(BannedDomain.domain.in_(domain_list)).all()] if not doms: diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 8ba32540a..2fa0b86c9 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -12,7 +12,7 @@ import signal import time db = db_session() -marseys = tuple(x[0] for x in db.query(Marsey.name).all()) +marseys = [x[0] for x in db.query(Marsey.name).all()] + ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','exclamationpoint','period','questionmark'] db.close() allowed_tags = tags = ['b', @@ -120,16 +120,16 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("@((\w|-){1,25})", sanitized, re.A): + for i in re.finditer("

@((\w|-){1,25})", sanitized, flags=re.A): u = get_user(i.group(1), graceful=True) if u: sanitized = sanitized.replace(i.group(0), f'''

@{u.username}''', 1) else: - sanitized = re.sub('(^|\s|\n|

)\/?((r|u)\/(\w|-){3,25})', r'\1/\2', sanitized, re.A) + sanitized = re.sub('(^|\s|\n|

)\/?((r|u)\/(\w|-){3,25})', r'\1/\2', sanitized, flags=re.A) - sanitized = re.sub('(^|\s|\n|

)\/?(s\/(\w|-){3,25})', r'\1/\2', sanitized, re.A) + sanitized = re.sub('(^|\s|\n|

)\/?(s\/(\w|-){3,25})', r'\1/\2', sanitized, flags=re.A) - for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})', sanitized, re.A): + for i in re.finditer('(^|\s|\n|

)@((\w|-){1,25})', sanitized, flags=re.A): u = get_user(i.group(2), graceful=True) if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1): @@ -165,7 +165,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): ] ).clean(sanitized) - soup = BeautifulSoup(sanitized, 'html.parser') + soup = BeautifulSoup(sanitized, 'lxml') for tag in soup.find_all("img"): if tag.get("src") and tag.get("class") != ['pp20']: @@ -184,7 +184,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): tag["target"] = "_blank" tag["rel"] = "nofollow noopener noreferrer" - if re.match("https?://\S+", str(tag.string), re.A): + if re.match("https?://\S+", str(tag.string), flags=re.A): try: tag.string = tag["href"] except: tag.string = "" @@ -195,9 +195,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if comment: marseys_used = set() - emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized, re.A)) + emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized, flags=re.A)) if len(emojis) > 20: edit = True + + captured = [] for i in emojis: + if i.group(0) in captured: continue + captured.append(i.group(0)) + 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() @@ -221,14 +226,19 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): if remoji == 'marseyrandom': remoji = choice(marseys) if path.isfile(f'files/assets/images/emojis/{remoji}.webp'): - new = re.sub(f'(?', new, re.I) + new = re.sub(f'(?', new, flags=re.I) if comment: marseys_used.add(emoji) sanitized = sanitized.replace(old, new) emojis = list(re.finditer('(? 20: edit = True + + captured = [] for i in emojis: + if i.group(0) in captured: continue + captured.append(i.group(0)) + emoji = i.group(1).lower().replace('#','') if emoji.startswith("!"): emoji = emoji[1:] @@ -240,7 +250,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, re.I) + sanitized = re.sub(f'(?', sanitized, flags=re.I) if comment: marseys_used.add(emoji) else: classes = 'emoji' @@ -251,7 +261,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, re.I) + sanitized = re.sub(f'(?', sanitized, flags=re.I) if comment: marseys_used.add(emoji) sanitized = sanitized.replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube") @@ -310,7 +320,12 @@ def filter_emojis_only(title, edit=False, graceful=False): emojis = list(re.finditer('(? 20: edit = True + + captured = [] for i in emojis: + if i.group(0) in captured: continue + captured.append(i.group(0)) + emoji = i.group(1).lower() if emoji.startswith("!"): @@ -323,7 +338,7 @@ def filter_emojis_only(title, edit=False, graceful=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, re.I) + title = re.sub(f'(?', title, flags=re.I) else: classes = 'emoji' @@ -334,7 +349,7 @@ def filter_emojis_only(title, edit=False, graceful=False): else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, re.I) + title = re.sub(f'(?', title, flags=re.I) title = re.sub('~~(.*?)~~', r'\1', title) diff --git a/files/routes/comments.py b/files/routes/comments.py index c9c25f392..6e87756ee 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -40,8 +40,6 @@ WORDLE_COLOR_MAPPINGS = {-1: "🟥", 0: "🟨", 1: "🟩"} def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) try: cid = int(cid) except: abort(404) @@ -145,7 +143,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None): def api_comment(v): if v.is_suspended: return {"error": "You can't perform this action while banned."}, 403 - if v.admin_level < 2: + if v.admin_level < 3: if v and v.patron: if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 @@ -181,7 +179,7 @@ def api_comment(v): f.write('\n{[para]}\n' + body) if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838): - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -190,16 +188,16 @@ def api_comment(v): if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, flags=re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') options = [] - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): options.append(i.group(1)) body = body.replace(i.group(0), "") choices = [] - for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, re.A): + for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A): choices.append(i.group(1)) body = body.replace(i.group(0), "") @@ -275,7 +273,7 @@ def api_comment(v): body_html = sanitize(body, comment=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 if parent_post.id not in (37696,37697,37749,37833,37838): if v.longpost: @@ -388,7 +386,7 @@ def api_comment(v): g.db.add(c_choice) if request.host == 'pcmemes.net' and c.body.lower().startswith("based"): - pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE) + pill = re.match("based and (.{1,20}?)(-| )pilled", body, flags=re.IGNORECASE) if level == 1: basedguy = get_account(parent_post.author_id) else: basedguy = get_account(c.parent_comment.author_id) @@ -695,7 +693,7 @@ def api_comment(v): @auth_required def edit_comment(cid, v): - if v.admin_level < 2: + if v.admin_level < 3: if v and v.patron: if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 @@ -711,20 +709,20 @@ def edit_comment(cid, v): if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1": if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403 - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, flags=re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username) if not c.options: - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): body = body.replace(i.group(0), "") c_option = Comment(author_id=AUTOPOLLER_ID, parent_submission=c.parent_submission, @@ -737,7 +735,7 @@ def edit_comment(cid, v): g.db.add(c_option) if not c.choices: - for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, re.A): + for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A): body = body.replace(i.group(0), "") c_choice = Comment(author_id=AUTOCHOICE_ID, parent_submission=c.parent_submission, @@ -751,7 +749,7 @@ def edit_comment(cid, v): body_html = sanitize(body, edit=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 diff --git a/files/routes/front.py b/files/routes/front.py index d214655d7..63ce2b56e 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -145,8 +145,6 @@ def front_all(v, sub=None): if not v and request.path == "/" and not request.headers.get("Authorization"): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) - try: page = max(int(request.values.get("page", 1)), 1) except: abort(400) diff --git a/files/routes/login.py b/files/routes/login.py index e551eb98f..0bed916da 100644 --- a/files/routes/login.py +++ b/files/routes/login.py @@ -25,7 +25,7 @@ def login_get(v): def check_for_alts(current_id): - ids = tuple(x[0] for x in g.db.query(User.id).all()) + ids = [x[0] for x in g.db.query(User.id).all()] past_accs = set(session.get("history", [])) for past_id in list(past_accs): @@ -338,7 +338,7 @@ def sign_up_post(v): password=request.values.get("password"), email=email, referred_by=ref_id or None, - ban_evade = int(any((x.is_banned or x.shadowbanned) and not x.unban_utc for x in g.db.query(User).filter(User.id.in_(tuple(session.get("history", [])))).all() if x)) + ban_evade = int(any((x.is_banned or x.shadowbanned) and not x.unban_utc for x in g.db.query(User).filter(User.id.in_(session.get("history", []))).all() if x)) ) g.db.add(new_user) diff --git a/files/routes/posts.py b/files/routes/posts.py index bf83bf938..03155e26e 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -21,13 +21,13 @@ from shutil import copyfile from sys import stdout db = db_session() -marseys = tuple(f':#{x[0]}:' for x in db.query(Marsey.name).all()) +marseys = [f':#{x[0]}:' for x in db.query(Marsey.name).all()] db.close() if path.exists(f'snappy_{SITE_NAME}.txt'): with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f: - if SITE == 'pcmemes.net': snappyquotes = tuple(f.read().split("{[para]}")) - else: snappyquotes = tuple(f.read().split("\n{[para]}\n")) + marseys + if SITE == 'pcmemes.net': snappyquotes = f.read().split("{[para]}") + else: snappyquotes = [f.read().split("\n{[para]}\n")] + marseys else: snappyquotes = marseys IMGUR_KEY = environ.get("IMGUR_KEY").strip() @@ -129,7 +129,7 @@ def submit_get(v, sub=None): if request.path.startswith('/s/') and not sub: abort(404) - SUBS = () if SITE_NAME == 'Drama' and not sub else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()) + SUBS = () if SITE_NAME == 'Drama' and not sub else [[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()] return render_template("submit.html", SUBS=SUBS, v=v, sub=sub, ghost=submit_ghost(v,g.db)) @@ -146,9 +146,6 @@ def post_id(pid, anything=None, v=None, sub=None): if not v and not request.path.startswith('/logged_out') and not request.headers.get("Authorization"): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) - - try: pid = int(pid) except Exception as e: pass @@ -444,7 +441,7 @@ def morecomments(v, cid): @limiter.limit("1/second;30/minute;200/hour;1000/day") @auth_required def edit_post(pid, v): - if v.admin_level < 2: + if v.admin_level < 3: if v and v.patron: if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 @@ -460,10 +457,10 @@ def edit_post(pid, v): if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403 if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403 if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -473,7 +470,7 @@ def edit_post(pid, v): if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username) title_html = filter_emojis_only(title, edit=True) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, re.A))): return {"error":"You can only type marseys!"}, 403 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, flags=re.A))): return {"error":"You can only type marseys!"}, 403 p.title = title[:500] p.title_html = title_html @@ -494,13 +491,13 @@ def edit_post(pid, v): else: return {"error": "Image/Video files only"}, 400 if body != p.body: - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, flags=re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username) if not p.options.count(): - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): body = body.replace(i.group(0), "") c = Comment(author_id=AUTOPOLLER_ID, parent_submission=p.id, @@ -512,7 +509,7 @@ def edit_post(pid, v): g.db.add(c) if not p.choices.count(): - for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, re.A): + for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A): body = body.replace(i.group(0), "") c = Comment(author_id=AUTOCHOICE_ID, parent_submission=p.id, @@ -535,7 +532,7 @@ def edit_post(pid, v): return {"error": reason}, 403 p.body = body - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return {"error":"You can only type marseys!"}, 40 + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 40 if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403 @@ -671,7 +668,7 @@ def thumbnail_thread(pid): if x.headers.get("Content-Type","").startswith("text/html"): - soup=BeautifulSoup(x.content, 'html.parser') + soup=BeautifulSoup(x.content, 'lxml') thumb_candidate_urls=[] @@ -788,7 +785,7 @@ def thumbnail_thread(pid): notif = Notification(comment_id=new_comment.id, user_id=admin.id) db.add(notif) - k,val = random.choice(tuple(REDDIT_NOTIFS.items())) + k,val = random.choice(REDDIT_NOTIFS.items()) for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={k}&size=1').json()["data"]: try: body_html = sanitize(f'New mention of you: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) except: continue @@ -859,7 +856,7 @@ def submit_post(v, sub=None): def error(error): if request.headers.get("Authorization") or request.headers.get("xhr"): return {"error": error}, 403 - SUBS = () if SITE_NAME == 'Drama' and not sub else tuple(x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()) + SUBS = () if SITE_NAME == 'Drama' and not sub else [x[0] for x in g.db.query(Sub.name).order_by(Sub.name).all()] return render_template("submit.html", SUBS=SUBS, v=v, error=error, title=title, url=url, body=body, ghost=submit_ghost(v,g.db)), 400 @@ -876,7 +873,7 @@ def submit_post(v, sub=None): if v.is_suspended: return error("You can't perform this action while banned.") - if v.admin_level < 2: + if v.admin_level < 3: if v and v.patron: if request.content_length > 8 * 1024 * 1024: return error( "Max file size is 4 MB (8 MB for paypigs).") elif request.content_length > 4 * 1024 * 1024: return error( "Max file size is 4 MB (8 MB for paypigs).") @@ -886,7 +883,7 @@ def submit_post(v, sub=None): title_html = filter_emojis_only(title, graceful=True) if len(title_html) > 1500: return error("Rendered title is too big!") - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, re.A))): return error("You can only type marseys!") + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, flags=re.A))): return error("You can only type marseys!") if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") @@ -898,10 +895,10 @@ def submit_post(v, sub=None): elif "/media.giphy.com/" in url or "/c.tenor.com/" in url: url = url.replace(".gif", ".webp") elif "/i.ibb.com/" in url: url = url.replace(".png", ".webp").replace(".jpg", ".webp").replace(".jpeg", ".webp").replace(".gif", ".webp") - for rd in ["://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it"]: + for rd in ("://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it", "://teddit.net"): url = url.replace(rd, "://old.reddit.com") - url = url.replace("old.reddit.com/gallery", "new.reddit.com/gallery").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.youtube", "https://youtube") + url = url.replace("nitter.net", "twitter.com").replace("old.reddit.com/gallery", "new.reddit.com/gallery").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube").replace("https://www.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/") @@ -972,10 +969,10 @@ def submit_post(v, sub=None): return error("There's a 500 character limit for titles.") if v.marseyawarded: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A)) if len(marregex) == 0: return error("You can only type marseys!") if body: - marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, re.A)) + marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A)) if len(marregex) == 0: return error("You can only type marseys!") if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") @@ -1041,22 +1038,22 @@ def submit_post(v, sub=None): if len(url) > 2048: return error("There's a 2048 character limit for URLs.") - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', body, flags=re.M|re.A): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') if v and v.admin_level > 2: bet_options = [] - for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, re.A): + for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, flags=re.A): bet_options.append(i.group(1)) body = body.replace(i.group(0), "") options = [] - for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, re.A): + for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A): options.append(i.group(1)) body = body.replace(i.group(0), "") choices = [] - for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, re.A): + for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A): choices.append(i.group(1)) body = body.replace(i.group(0), "") @@ -1084,7 +1081,7 @@ def submit_post(v, sub=None): body_html = sanitize(body) - if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, re.A))): return error("You can only type marseys!") + if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return error("You can only type marseys!") if v.longpost: if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!") diff --git a/files/routes/search.py b/files/routes/search.py index d062eaf28..d18689104 100644 --- a/files/routes/search.py +++ b/files/routes/search.py @@ -5,7 +5,7 @@ from flask import * from files.__main__ import app -query_regex=re.compile("(\w+):(\S+)", re.A) +query_regex=re.compile("(\w+):(\S+)", flags=re.A) valid_params=[ 'author', 'domain', @@ -88,7 +88,6 @@ def searchposts(v): if 'q' in criteria: words=criteria['q'].split() words=[Submission.title.ilike('%'+x+'%') for x in words] - words=tuple(words) posts=posts.filter(*words) if 'over18' in criteria: posts = posts.filter(Submission.over_18==True) @@ -225,7 +224,6 @@ def searchcomments(v): if 'q' in criteria: words = criteria['q'].split() words = [Comment.body.ilike('%'+x+'%') for x in words] - words = tuple(words) comments = comments.filter(*words) if 'over18' in criteria: comments = comments.filter(Comment.over_18 == True) diff --git a/files/routes/settings.py b/files/routes/settings.py index 0445ef777..48f8879b7 100644 --- a/files/routes/settings.py +++ b/files/routes/settings.py @@ -46,8 +46,8 @@ def removebackground(v): @auth_required def settings_profile_post(v): if v and v.patron: - if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 - elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413 + if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 + elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 updated = False @@ -143,7 +143,7 @@ def settings_profile_post(v): elif (v.patron or v.id == MOOSE_ID) and request.values.get("sig"): sig = request.values.get("sig")[:200] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', sig, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', sig, flags=re.M|re.A): if "wikipedia" not in i.group(1): sig = sig.replace(i.group(1), f'![]({i.group(1)})') sig_html = sanitize(sig) @@ -177,7 +177,7 @@ def settings_profile_post(v): elif request.values.get("friends"): friends = request.values.get("friends")[:500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', friends, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', friends, flags=re.M|re.A): if "wikipedia" not in i.group(1): friends = friends.replace(i.group(1), f'![]({i.group(1)})') friends_html = sanitize(friends) @@ -214,7 +214,7 @@ def settings_profile_post(v): elif request.values.get("enemies"): enemies = request.values.get("enemies")[:500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', enemies, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', enemies, flags=re.M|re.A): if "wikipedia" not in i.group(1): enemies = enemies.replace(i.group(1), f'![]({i.group(1)})') enemies_html = sanitize(enemies) @@ -251,7 +251,7 @@ def settings_profile_post(v): elif request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1": bio = request.values.get("bio")[:1500] - for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', bio, re.M|re.A): + for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))', bio, flags=re.M|re.A): if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'![]({i.group(1)})') if request.files.get('file'): @@ -631,8 +631,8 @@ def settings_log_out_others(v): @auth_required def settings_images_profile(v): if v and v.patron: - if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 - elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413 + if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 + elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 if request.headers.get("cf-ipcountry") == "T1": return {"error":"Image uploads are not allowed through TOR."}, 403 @@ -670,8 +670,8 @@ def settings_images_profile(v): @auth_required def settings_images_banner(v): if v and v.patron: - if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 - elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413 + if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 + elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 if request.headers.get("cf-ipcountry") == "T1": return {"error":"Image uploads are not allowed through TOR."}, 403 diff --git a/files/routes/static.py b/files/routes/static.py index 17737adc1..8f4b916a2 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -39,7 +39,6 @@ def marsey_list(): @auth_desired def terms(v): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) return render_template("terms.html", v=v) @@ -48,7 +47,6 @@ def terms(v): @auth_desired def sidebar(v): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) return render_template('sidebar.html', v=v) @@ -65,7 +63,6 @@ def stats(): day = int(time.time()) - 86400 week = int(time.time()) - 604800 - active_users = set() posters = g.db.query(Submission.author_id).distinct(Submission.author_id).filter(Submission.created_utc > week).all() commenters = g.db.query(Comment.author_id).distinct(Comment.author_id).filter(Comment.created_utc > week).all() voters = g.db.query(Vote.user_id).distinct(Vote.user_id).filter(Vote.created_utc > week).all() diff --git a/files/routes/subs.py b/files/routes/subs.py index 2b373355d..ebad48984 100644 --- a/files/routes/subs.py +++ b/files/routes/subs.py @@ -371,8 +371,8 @@ def get_sub_css(sub): @is_not_permabanned def sub_banner(v, sub): if v and v.patron: - if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 - elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413 + if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 + elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 if request.headers.get("cf-ipcountry") == "T1": return {"error":"Image uploads are not allowed through TOR."}, 403 @@ -402,8 +402,8 @@ def sub_banner(v, sub): @is_not_permabanned def sub_sidebar(v, sub): if v and v.patron: - if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 8 MB."}, 413 - elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB."}, 413 + if request.content_length > 8 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 + elif request.content_length > 4 * 1024 * 1024: return {"error":"Max file size is 4 MB (8 MB for paypigs)."}, 413 if request.headers.get("cf-ipcountry") == "T1": return {"error":"Image uploads are not allowed through TOR."}, 403 diff --git a/files/routes/users.py b/files/routes/users.py index 7cf4e19a0..bf8a09ade 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -685,8 +685,6 @@ def u_username(username, v=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) - u = get_user(username, v=v) @@ -784,8 +782,6 @@ def u_username_comments(username, v=None): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) - user = get_user(username, v=v) if username != user.username: return redirect(f'{SITE_FULL}/@{user.username}/comments') @@ -970,7 +966,6 @@ def remove_follow(username, v): @auth_desired def user_profile_uid(v, id): if not v and not request.path.startswith('/logged_out'): return redirect(f"{SITE_FULL}/logged_out{request.full_path}") - if v and request.path.startswith('/logged_out'): return redirect(SITE_FULL + request.full_path.replace('/logged_out','')) try: id = int(id) except: abort(404) diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html index 9e84d3f17..7b8b69f03 100644 --- a/files/templates/emoji_modal.html +++ b/files/templates/emoji_modal.html @@ -106,4 +106,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/files/templates/marseys.html b/files/templates/marseys.html index e78708344..2f4206d35 100644 --- a/files/templates/marseys.html +++ b/files/templates/marseys.html @@ -20,7 +20,7 @@ {{loop.index}} {{marsey.name}} - :{{marsey.name}}: + :{{marsey.name}}: {{marsey.count}} {{author.username}} @@ -30,7 +30,7 @@ {{loop.index}} {{marsey.name}} - :{{marsey.name}}: + :{{marsey.name}}: {{marsey.count}} {% endfor %} diff --git a/files/templates/submission.html b/files/templates/submission.html index d8dd2ddfc..270a8187d 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -18,6 +18,8 @@ history.pushState(null, null, '{{p.permalink}}'); localStorage.setItem("post_title", "") localStorage.setItem("post_text", "") + localStorage.setItem("post_url", "") + localStorage.setItem("sub", "") {% endif %}