vvvvvvvvvvvvvvv
This commit is contained in:
parent
46f29624cb
commit
09fe6f5a07
8 changed files with 30 additions and 30 deletions
|
@ -201,9 +201,9 @@ class Submission(Base):
|
||||||
|
|
||||||
output = self.title.lower()
|
output = self.title.lower()
|
||||||
|
|
||||||
output = re.sub('&\w{2,3};', '', output)
|
output = re.sub('&\w{2,3};', '', output, flags=re.A)
|
||||||
|
|
||||||
output = [re.sub('\W', '', word) for word in output.split()]
|
output = [re.sub('\W', '', word, flags=re.A) for word in output.split()]
|
||||||
output = [x for x in output if x][:6]
|
output = [x for x in output if x][:6]
|
||||||
|
|
||||||
output = '-'.join(output)
|
output = '-'.join(output)
|
||||||
|
|
|
@ -82,7 +82,7 @@ def NOTIFY_USERS2(text, v):
|
||||||
if id == 0: continue
|
if id == 0: continue
|
||||||
if word in text.lower() and id not in notify_users and v.id != id: notify_users.add(id)
|
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):
|
for i in re.finditer("(^|\s|\n)@((\w|-){1,25})", text, flags=re.A):
|
||||||
user = get_user(i.group(2), graceful=True)
|
user = get_user(i.group(2), graceful=True)
|
||||||
if user and not v.any_block_exists(user): notify_users.add(user.id)
|
if user and not v.any_block_exists(user): notify_users.add(user.id)
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ SLURS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
|
single_words = "|".join([slur.lower() for slur in SLURS.keys()])
|
||||||
SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)")
|
SLUR_REGEX = re.compile(rf"(?i)((?<=\s|>)|^)({single_words})((?=[\s<,.]|s[\s<,.])|$)", flags=re.A)
|
||||||
|
|
||||||
def sub_matcher(match: re.Match):
|
def sub_matcher(match: re.Match):
|
||||||
return SLURS[match.group(0).lower()]
|
return SLURS[match.group(0).lower()]
|
||||||
|
@ -109,8 +109,8 @@ def censor_slurs(body: str, logged_user):
|
||||||
def torture_ap(body, username):
|
def torture_ap(body, username):
|
||||||
body = SLUR_REGEX.sub(sub_matcher, body)
|
body = SLUR_REGEX.sub(sub_matcher, body)
|
||||||
for k, l in AJ_REPLACEMENTS.items(): body = body.replace(k, l)
|
for k, l in AJ_REPLACEMENTS.items(): body = body.replace(k, l)
|
||||||
body = re.sub('(^|\s|\n)(i|me) ', rf'\1@{username} ', body, flags=re.I)
|
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)
|
body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, flags=re.I|re.A)
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -105,14 +105,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("<script","").replace('','')
|
sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("<script","").replace('','')
|
||||||
|
|
||||||
if alert:
|
if alert:
|
||||||
for i in re.finditer("<p>@((\w|-){1,25})", sanitized):
|
for i in re.finditer("<p>@((\w|-){1,25})", sanitized, flags=re.A):
|
||||||
u = get_user(i.group(1), graceful=True)
|
u = get_user(i.group(1), graceful=True)
|
||||||
if u:
|
if u:
|
||||||
sanitized = sanitized.replace(i.group(0), f'''<p><a href="/id/{u.id}"><img alt="@{u.username}'s profile picture" loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>''', 1)
|
sanitized = sanitized.replace(i.group(0), f'''<p><a href="/id/{u.id}"><img alt="@{u.username}'s profile picture" loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>''', 1)
|
||||||
else:
|
else:
|
||||||
sanitized = re.sub('(^|\s|\n|<p>)\/?((r|u)\/(\w|-){3,25})', r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener noreferrer">\2</a>', sanitized)
|
sanitized = re.sub('(^|\s|\n|<p>)\/?((r|u)\/(\w|-){3,25})', r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener noreferrer">\2</a>', sanitized, flags=re.A)
|
||||||
|
|
||||||
for i in re.finditer('(^|\s|\n|<p>)@((\w|-){1,25})', sanitized):
|
for i in re.finditer('(^|\s|\n|<p>)@((\w|-){1,25})', sanitized, flags=re.A):
|
||||||
u = get_user(i.group(2), graceful=True)
|
u = get_user(i.group(2), graceful=True)
|
||||||
|
|
||||||
if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1):
|
if u and (not g.v.any_block_exists(u) or g.v.admin_level > 1):
|
||||||
|
@ -168,7 +168,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
tag["target"] = "_blank"
|
tag["target"] = "_blank"
|
||||||
tag["rel"] = "nofollow noopener noreferrer"
|
tag["rel"] = "nofollow noopener noreferrer"
|
||||||
|
|
||||||
if re.match("https?://\S+", str(tag.string)):
|
if re.match("https?://\S+", str(tag.string), flags=re.A):
|
||||||
try: tag.string = tag["href"]
|
try: tag.string = tag["href"]
|
||||||
except: tag.string = ""
|
except: tag.string = ""
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
|
|
||||||
if comment: marseys_used = set()
|
if comment: marseys_used = set()
|
||||||
|
|
||||||
emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized))
|
emojis = list(re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized, flags=re.A))
|
||||||
if len(emojis) > 20: edit = True
|
if len(emojis) > 20: edit = True
|
||||||
for i in emojis:
|
for i in emojis:
|
||||||
old = i.group(0)
|
old = i.group(0)
|
||||||
|
|
|
@ -164,7 +164,7 @@ def api_comment(v):
|
||||||
f.write('\n{[para]}\n' + body)
|
f.write('\n{[para]}\n' + body)
|
||||||
|
|
||||||
if v.marseyawarded:
|
if v.marseyawarded:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body))
|
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 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
|
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -176,7 +176,7 @@ def api_comment(v):
|
||||||
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ def api_comment(v):
|
||||||
|
|
||||||
body_html = sanitize(body, comment=True)
|
body_html = sanitize(body, comment=True)
|
||||||
|
|
||||||
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))): 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 v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -604,7 +604,7 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
if body != c.body or request.files.get("file") and request.headers.get("cf-ipcountry") != "T1":
|
||||||
if v.marseyawarded:
|
if v.marseyawarded:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body))
|
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 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
|
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -616,7 +616,7 @@ def edit_comment(cid, v):
|
||||||
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
||||||
|
|
||||||
if not c.options:
|
if not c.options:
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
c_option = Comment(author_id=AUTOPOLLER_ID,
|
c_option = Comment(author_id=AUTOPOLLER_ID,
|
||||||
parent_submission=c.parent_submission,
|
parent_submission=c.parent_submission,
|
||||||
|
@ -630,7 +630,7 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
body_html = sanitize(body, edit=True)
|
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
|
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 v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
|
|
@ -266,7 +266,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
|
||||||
|
|
||||||
if sort == "hot":
|
if sort == "hot":
|
||||||
ti = int(time.time()) + 3600
|
ti = int(time.time()) + 3600
|
||||||
posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.23)))
|
posts = posts.order_by(-1000000*(Submission.realupvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23)))
|
||||||
elif sort == "new":
|
elif sort == "new":
|
||||||
posts = posts.order_by(Submission.created_utc.desc())
|
posts = posts.order_by(Submission.created_utc.desc())
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
|
|
|
@ -407,10 +407,10 @@ def edit_post(pid, v):
|
||||||
if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403
|
if len(body) > 20000: return {"error":"Character limit is 20000!"}, 403
|
||||||
|
|
||||||
if v.marseyawarded:
|
if v.marseyawarded:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title))
|
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 len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
|
||||||
if body:
|
if body:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body))
|
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 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
|
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -420,7 +420,7 @@ def edit_post(pid, v):
|
||||||
if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username)
|
if v.agendaposter and not v.marseyawarded: title = torture_ap(title, v.username)
|
||||||
|
|
||||||
title_html = filter_emojis_only(title, edit=True)
|
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
|
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 = title[:500]
|
||||||
p.title_html = title_html
|
p.title_html = title_html
|
||||||
|
|
||||||
|
@ -447,7 +447,7 @@ def edit_post(pid, v):
|
||||||
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
||||||
|
|
||||||
if not p.options.count():
|
if not p.options.count():
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
c = Comment(author_id=AUTOPOLLER_ID,
|
c = Comment(author_id=AUTOPOLLER_ID,
|
||||||
parent_submission=p.id,
|
parent_submission=p.id,
|
||||||
|
@ -470,7 +470,7 @@ def edit_post(pid, v):
|
||||||
return {"error": reason}, 403
|
return {"error": reason}, 403
|
||||||
|
|
||||||
p.body = body
|
p.body = body
|
||||||
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))): 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 v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -682,7 +682,7 @@ def submit_post(v):
|
||||||
title_html = filter_emojis_only(title)
|
title_html = filter_emojis_only(title)
|
||||||
body = request.values.get("body", "").strip().replace('','')
|
body = request.values.get("body", "").strip().replace('','')
|
||||||
|
|
||||||
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html))): return {"error":"You can only type marseys!"}, 40
|
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', title_html, flags=re.A))): return {"error":"You can only type marseys!"}, 40
|
||||||
|
|
||||||
if v.longpost:
|
if v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -770,10 +770,10 @@ def submit_post(v):
|
||||||
else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400
|
else: render_template("submit.html", v=v, error="500 character limit for titles.", title=title[:500], url=url, body=request.values.get("body", "")), 400
|
||||||
|
|
||||||
if v.marseyawarded:
|
if v.marseyawarded:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title))
|
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 len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
|
||||||
if body:
|
if body:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body))
|
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 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
|
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
@ -848,12 +848,12 @@ def submit_post(v):
|
||||||
|
|
||||||
if v and v.admin_level > 2:
|
if v and v.admin_level > 2:
|
||||||
bet_options = []
|
bet_options = []
|
||||||
for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body):
|
for i in re.finditer('\s*\$\$\$([^\$\n]+)\$\$\$\s*', body, flags=re.A):
|
||||||
bet_options.append(i.group(1))
|
bet_options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
@ -878,7 +878,7 @@ def submit_post(v):
|
||||||
|
|
||||||
body_html = sanitize(body)
|
body_html = sanitize(body)
|
||||||
|
|
||||||
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html))): return {"error":"You can only type marseys!"}, 400
|
if v.marseyawarded and len(list(re.finditer('>[^<\s+]|[^>\s+]<', body_html, flags=re.A))): return {"error":"You can only type marseys!"}, 400
|
||||||
|
|
||||||
if v.longpost:
|
if v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return {"error":"You have to type more than 280 characters!"}, 403
|
||||||
|
|
|
@ -5,7 +5,7 @@ from flask import *
|
||||||
from files.__main__ import app
|
from files.__main__ import app
|
||||||
|
|
||||||
|
|
||||||
query_regex=re.compile("(\w+):(\S+)")
|
query_regex=re.compile("(\w+):(\S+)", flags=re.A)
|
||||||
valid_params=[
|
valid_params=[
|
||||||
'author',
|
'author',
|
||||||
'domain',
|
'domain',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue