regex
This commit is contained in:
parent
d62fffe294
commit
b1f996f0b6
10 changed files with 83 additions and 111 deletions
|
@ -214,11 +214,10 @@ class Submission(Base):
|
||||||
|
|
||||||
if self.club: return link + '/-'
|
if self.club: return link + '/-'
|
||||||
|
|
||||||
output = self.title.lower()
|
output = title_regex.sub('', self.title.lower())
|
||||||
output = re.sub('&\w{2,3};', '', output, flags=re.A)
|
output = output.split()[:6]
|
||||||
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)
|
output = '-'.join(output)
|
||||||
|
|
||||||
if not output: output = '-'
|
if not output: output = '-'
|
||||||
|
|
||||||
return f"{link}/{output}"
|
return f"{link}/{output}"
|
||||||
|
|
|
@ -67,22 +67,7 @@ def NOTIFY_USERS(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)
|
||||||
|
|
||||||
soup = BeautifulSoup(text, 'lxml')
|
for i in mention_regex.finditer(text):
|
||||||
for mention in soup.find_all("a", href=re.compile("^\/id\/([0-9]+)", flags=re.A)):
|
|
||||||
id = int(mention["href"].split("/id/")[1])
|
|
||||||
if id != v.id:
|
|
||||||
user = g.db.query(User).filter_by(id=id).one_or_none()
|
|
||||||
if user and not v.any_block_exists(user): notify_users.add(user.id)
|
|
||||||
|
|
||||||
return notify_users
|
|
||||||
|
|
||||||
def NOTIFY_USERS2(text, v):
|
|
||||||
notify_users = set()
|
|
||||||
for word, id in NOTIFIED_USERS.items():
|
|
||||||
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, 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)
|
||||||
|
|
||||||
|
|
|
@ -107,29 +107,6 @@ 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"((?<=\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()]
|
|
||||||
|
|
||||||
def sub_matcher_upper(match):
|
|
||||||
return SLURS[match.group(0).lower()].upper()
|
|
||||||
|
|
||||||
def censor_slurs(body, logged_user):
|
|
||||||
if not logged_user or logged_user.slurreplacer:
|
|
||||||
body = SLUR_REGEX_UPPER.sub(sub_matcher_upper, body)
|
|
||||||
body = SLUR_REGEX.sub(sub_matcher, body)
|
|
||||||
return body
|
|
||||||
|
|
||||||
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, flags=re.I|re.A)
|
|
||||||
body = re.sub("(^|\s|\n)i'm ", rf'\1@{username} is ', body, flags=re.I|re.A)
|
|
||||||
return body
|
|
||||||
|
|
||||||
|
|
||||||
LONGPOST_REPLIES = ('Wow, you must be a JP fan.', 'This is one of the worst posts I have EVER seen. Delete it.', "No, don't reply like this, please do another wall of unhinged rant please.", '# 😴😴😴', "Ma'am we've been over this before. You need to stop.", "I've known more coherent downies.", "Your pulitzer's in the mail", "That's great and all, but I asked for my burger without cheese.", 'That degree finally paying off', "That's nice sweaty. Why don't you have a seat in the time out corner with Pizzashill until you calm down, then you can have your Capri Sun.", "All them words won't bring your pa back.", "You had a chance to not be completely worthless, but it looks like you threw it away. At least you're consistent.", 'Some people are able to display their intelligence by going on at length on a subject and never actually saying anything. This ability is most common in trades such as politics, public relations, and law. You have impressed me by being able to best them all, while still coming off as an absolute idiot.', "You can type 10,000 characters and you decided that these were the one's that you wanted.", 'Have you owned the libs yet?', "I don't know what you said, because I've seen another human naked.", 'Impressive. Normally people with such severe developmental disabilities struggle to write much more than a sentence or two. He really has exceded our expectations for the writing portion. Sadly the coherency of his writing, along with his abilities in the social skills and reading portions, are far behind his peers with similar disabilities.', "This is a really long way of saying you don't fuck.", "Sorry ma'am, looks like his delusions have gotten worse. We'll have to admit him.", ':#marseywoah:', 'If only you could put that energy into your relationships', 'Posts like this is why I do Heroine.', 'still unemployed then?', 'K', 'look im gunna have 2 ask u 2 keep ur giant dumps in the toilet not in my replys 😷😷😷', "Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures.", "Good job bobby, here's a star", "That was a mistake. You're about to find out the hard way why.", f'You sat down and wrote all this shit. You could have done so many other things with your life. What happened to your life that made you decide writing novels of bullshit on {SITE} was the best option?', "I don't have enough spoons to read this shit", "All those words won't bring daddy back.", 'OUT!', "Damn, you're really mad over this, but thanks for the effort you put into typing that all out! Sadly I won't read it all.", "Jesse what the fuck are you talking about??", "▼you're fucking bananas if you think I'm reading all that, take my downvote and shut up idiot")
|
LONGPOST_REPLIES = ('Wow, you must be a JP fan.', 'This is one of the worst posts I have EVER seen. Delete it.', "No, don't reply like this, please do another wall of unhinged rant please.", '# 😴😴😴', "Ma'am we've been over this before. You need to stop.", "I've known more coherent downies.", "Your pulitzer's in the mail", "That's great and all, but I asked for my burger without cheese.", 'That degree finally paying off', "That's nice sweaty. Why don't you have a seat in the time out corner with Pizzashill until you calm down, then you can have your Capri Sun.", "All them words won't bring your pa back.", "You had a chance to not be completely worthless, but it looks like you threw it away. At least you're consistent.", 'Some people are able to display their intelligence by going on at length on a subject and never actually saying anything. This ability is most common in trades such as politics, public relations, and law. You have impressed me by being able to best them all, while still coming off as an absolute idiot.', "You can type 10,000 characters and you decided that these were the one's that you wanted.", 'Have you owned the libs yet?', "I don't know what you said, because I've seen another human naked.", 'Impressive. Normally people with such severe developmental disabilities struggle to write much more than a sentence or two. He really has exceded our expectations for the writing portion. Sadly the coherency of his writing, along with his abilities in the social skills and reading portions, are far behind his peers with similar disabilities.', "This is a really long way of saying you don't fuck.", "Sorry ma'am, looks like his delusions have gotten worse. We'll have to admit him.", ':#marseywoah:', 'If only you could put that energy into your relationships', 'Posts like this is why I do Heroine.', 'still unemployed then?', 'K', 'look im gunna have 2 ask u 2 keep ur giant dumps in the toilet not in my replys 😷😷😷', "Mommy is soooo proud of you, sweaty. Let's put this sperg out up on the fridge with all your other failures.", "Good job bobby, here's a star", "That was a mistake. You're about to find out the hard way why.", f'You sat down and wrote all this shit. You could have done so many other things with your life. What happened to your life that made you decide writing novels of bullshit on {SITE} was the best option?', "I don't have enough spoons to read this shit", "All those words won't bring daddy back.", 'OUT!', "Damn, you're really mad over this, but thanks for the effort you put into typing that all out! Sadly I won't read it all.", "Jesse what the fuck are you talking about??", "▼you're fucking bananas if you think I'm reading all that, take my downvote and shut up idiot")
|
||||||
|
|
||||||
|
@ -670,7 +647,51 @@ db = db_session()
|
||||||
marseys_const = [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']
|
marseys_const = [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()
|
db.close()
|
||||||
|
|
||||||
if SITE_NAME == 'PCM': valid_username_regex = re.compile("^[a-zA-Z0-9_\-А-я]{3,25}$")
|
if SITE_NAME == 'PCM':
|
||||||
else: valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$")
|
valid_username_regex = re.compile("^[a-zA-Z0-9_\-А-я]{3,25}$", flags=re.A)
|
||||||
|
mention_regex = re.compile('(^|\s|\n|<p>)@(([a-zA-Z0-9_\-А-я]){3,25})', flags=re.A)
|
||||||
|
else:
|
||||||
|
valid_username_regex = re.compile("^[a-zA-Z0-9_\-]{3,25}$", flags=re.A)
|
||||||
|
mention_regex = re.compile('(^|\s|\n|<p>)@(([a-zA-Z0-9_\-]){1,25})', flags=re.A)
|
||||||
|
|
||||||
valid_password_regex = re.compile("^.{8,100}$", flags=re.A)
|
valid_password_regex = re.compile("^.{8,100}$", flags=re.A)
|
||||||
|
|
||||||
|
marsey_regex = re.compile("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", flags=re.A)
|
||||||
|
|
||||||
|
image_regex = re.compile("(^https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999)($|\s|\n))", flags=re.M|re.A)
|
||||||
|
|
||||||
|
valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A)
|
||||||
|
|
||||||
|
query_regex = re.compile("(\w+):(\S+)", flags=re.A)
|
||||||
|
|
||||||
|
poll_regex = re.compile("\s*\$\$([^\$\n]+)\$\$\s*", flags=re.A)
|
||||||
|
choice_regex = re.compile("\s*&&([^\$\n]+)&&\s*", flags=re.A)
|
||||||
|
|
||||||
|
embed_removing_regex = re.compile('!\[\]\((.*?)\)', flags=re.A)
|
||||||
|
|
||||||
|
title_regex = re.compile("[^\w ]", flags=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)
|
||||||
|
torture_regex = re.compile('(^|\s|\n)(i|me) ', flags=re.I|re.A)
|
||||||
|
torture_regex2 = re.compile("(^|\s|\n)i'm ", flags=re.I|re.A)
|
||||||
|
|
||||||
|
def sub_matcher(match):
|
||||||
|
return SLURS[match.group(0).lower()]
|
||||||
|
|
||||||
|
def sub_matcher_upper(match):
|
||||||
|
return SLURS[match.group(0).lower()].upper()
|
||||||
|
|
||||||
|
def censor_slurs(body, logged_user):
|
||||||
|
if not logged_user or logged_user.slurreplacer:
|
||||||
|
body = slur_regex_upper.sub(sub_matcher_upper, body)
|
||||||
|
body = slur_regex.sub(sub_matcher, body)
|
||||||
|
return body
|
||||||
|
|
||||||
|
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 = torture_regex.sub(rf'\1@{username} ', body)
|
||||||
|
body = torture_regex2.sub(rf'\1@{username} is ', body)
|
||||||
|
return body
|
||||||
|
|
|
@ -11,9 +11,6 @@ from random import random, choice
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
||||||
if SITE == 'PCM': mention_regex = re.compile('(^|\s|\n|<p>)@(([a-zA-Z0-9_\-А-я]){3,25})', flags=re.A)
|
|
||||||
else: mention_regex = re.compile('(^|\s|\n|<p>)@(([a-zA-Z0-9_\-]){1,25})', flags=re.A)
|
|
||||||
|
|
||||||
allowed_tags = tags = ['b',
|
allowed_tags = tags = ['b',
|
||||||
'blockquote',
|
'blockquote',
|
||||||
'br',
|
'br',
|
||||||
|
|
|
@ -209,8 +209,7 @@ def api_comment(v):
|
||||||
f.write('\n{[para]}\n' + body)
|
f.write('\n{[para]}\n' + body)
|
||||||
|
|
||||||
if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838):
|
if v.marseyawarded and parent_post.id not in (37696,37697,37749,37833,37838):
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A))
|
if not marsey_regex.fullmatch(body): 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
|
||||||
elif v.bird and len(body) > 140 and parent_post.id not in (37696,37697,37749,37833,37838):
|
elif v.bird and len(body) > 140 and parent_post.id not in (37696,37697,37749,37833,37838):
|
||||||
|
@ -218,16 +217,15 @@ def api_comment(v):
|
||||||
|
|
||||||
if not body and not request.files.get('file'): return {"error":"You need to actually write something!"}, 400
|
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, flags=re.M|re.A):
|
body = image_regex.sub(r'', body)
|
||||||
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, flags=re.A):
|
for i in poll_regex.finditer(body):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
choices = []
|
choices = []
|
||||||
for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A):
|
for i in choice_regex.finditer(body):
|
||||||
choices.append(i.group(1))
|
choices.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
@ -304,8 +302,6 @@ 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, flags=re.A))): return {"error":"You can only type marseys!"}, 403
|
|
||||||
|
|
||||||
if parent_post.id not in (37696,37697,37749,37833,37838):
|
if parent_post.id not in (37696,37697,37749,37833,37838):
|
||||||
if v.longpost:
|
if v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('):
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('):
|
||||||
|
@ -622,7 +618,7 @@ def api_comment(v):
|
||||||
|
|
||||||
|
|
||||||
if not v.shadowbanned:
|
if not v.shadowbanned:
|
||||||
notify_users = NOTIFY_USERS(body_html, v)
|
notify_users = NOTIFY_USERS(body, v)
|
||||||
|
|
||||||
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
|
for x in g.db.query(Subscription.user_id).filter_by(submission_id=c.parent_submission).all(): notify_users.add(x[0])
|
||||||
|
|
||||||
|
@ -716,21 +712,19 @@ def edit_comment(cid, v):
|
||||||
return {"error":"You have to actually type something!"}, 400
|
return {"error":"You have to actually type something!"}, 400
|
||||||
|
|
||||||
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 and not marsey_regex.fullmatch(body):
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", body, flags=re.A))
|
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
|
||||||
elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 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, flags=re.M|re.A):
|
body = image_regex.sub(r'', body)
|
||||||
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
if v.agendaposter and not v.marseyawarded:
|
if v.agendaposter and not v.marseyawarded:
|
||||||
body = torture_ap(body, v.username)
|
body = torture_ap(body, v.username)
|
||||||
|
|
||||||
if not c.options:
|
if not c.options:
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
for i in poll_regex.finditer(body):
|
||||||
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,
|
||||||
|
@ -743,7 +737,7 @@ def edit_comment(cid, v):
|
||||||
g.db.add(c_option)
|
g.db.add(c_option)
|
||||||
|
|
||||||
if not c.choices:
|
if not c.choices:
|
||||||
for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A):
|
for i in choice_regex.finditer(body):
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
c_choice = Comment(author_id=AUTOCHOICE_ID,
|
c_choice = Comment(author_id=AUTOCHOICE_ID,
|
||||||
parent_submission=c.parent_submission,
|
parent_submission=c.parent_submission,
|
||||||
|
@ -757,8 +751,6 @@ 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, 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
|
||||||
elif v.bird:
|
elif v.bird:
|
||||||
|
@ -896,7 +888,7 @@ def edit_comment(cid, v):
|
||||||
|
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(body_html, v)
|
notify_users = NOTIFY_USERS(body, v)
|
||||||
|
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
notif = g.db.query(Notification).filter_by(comment_id=c.id, user_id=x).one_or_none()
|
||||||
|
|
|
@ -95,7 +95,7 @@ def publish(pid, v):
|
||||||
g.db.add(post)
|
g.db.add(post)
|
||||||
|
|
||||||
if not post.ghost:
|
if not post.ghost:
|
||||||
notify_users = NOTIFY_USERS(post.body_html, v) | NOTIFY_USERS2(post.title, v)
|
notify_users = NOTIFY_USERS(f'{post.title} {post.body}', v)
|
||||||
|
|
||||||
text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})"
|
text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})"
|
||||||
if post.sub: text += f" in <a href='/s/{post.sub}'>/s/{post.sub}"
|
if post.sub: text += f" in <a href='/s/{post.sub}'>/s/{post.sub}"
|
||||||
|
@ -460,12 +460,8 @@ 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 and (not marsey_regex.fullmatch(title) or body and not marsey_regex.fullmatch(body)):
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", title, flags=re.A))
|
return {"error":"You can only type marseys!"}, 403
|
||||||
if len(marregex) == 0: return {"error":"You can only type marseys!"}, 403
|
|
||||||
if body:
|
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\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
|
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
|
elif v.bird and len(body) > 140: return {"error":"You have to type less than 140 characters!"}, 403
|
||||||
|
@ -474,7 +470,6 @@ 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, 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
|
||||||
|
|
||||||
|
@ -496,13 +491,12 @@ def edit_post(pid, v):
|
||||||
else: return {"error": "Image/Video files only"}, 400
|
else: return {"error": "Image/Video files only"}, 400
|
||||||
|
|
||||||
if body != p.body:
|
if body != p.body:
|
||||||
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):
|
body = image_regex.sub(r'', body)
|
||||||
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
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, flags=re.A):
|
for i in poll_regex.finditer(body):
|
||||||
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,
|
||||||
|
@ -514,7 +508,7 @@ def edit_post(pid, v):
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
|
|
||||||
if not p.choices.count():
|
if not p.choices.count():
|
||||||
for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A):
|
for i in choice_regex.finditer(body):
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
c = Comment(author_id=AUTOCHOICE_ID,
|
c = Comment(author_id=AUTOCHOICE_ID,
|
||||||
parent_submission=p.id,
|
parent_submission=p.id,
|
||||||
|
@ -537,7 +531,6 @@ 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, 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
|
||||||
|
@ -608,7 +601,7 @@ def edit_post(pid, v):
|
||||||
|
|
||||||
|
|
||||||
if not p.private and not p.ghost:
|
if not p.private and not p.ghost:
|
||||||
notify_users = NOTIFY_USERS(body_html, v) | NOTIFY_USERS2(title, v)
|
notify_users = NOTIFY_USERS(f'{title} {body}', v)
|
||||||
cid = notif_comment(f"@{v.username} has mentioned you: [{p.title}]({p.shortlink})")
|
cid = notif_comment(f"@{v.username} has mentioned you: [{p.title}]({p.shortlink})")
|
||||||
for x in notify_users:
|
for x in notify_users:
|
||||||
add_notif(cid, x)
|
add_notif(cid, x)
|
||||||
|
@ -885,8 +878,6 @@ def submit_post(v, sub=None):
|
||||||
title_html = filter_emojis_only(title, graceful=True)
|
title_html = filter_emojis_only(title, graceful=True)
|
||||||
if len(title_html) > 1500: return error("Rendered title is too big!")
|
if len(title_html) > 1500: return error("Rendered title is too big!")
|
||||||
|
|
||||||
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 v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")
|
||||||
elif v.bird:
|
elif v.bird:
|
||||||
|
@ -969,12 +960,8 @@ def submit_post(v, sub=None):
|
||||||
elif len(title) > 500:
|
elif len(title) > 500:
|
||||||
return error("There's a 500 character limit for titles.")
|
return error("There's a 500 character limit for titles.")
|
||||||
|
|
||||||
if v.marseyawarded:
|
if v.marseyawarded and (not marsey_regex.fullmatch(title) or body and not marsey_regex.fullmatch(body)):
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", title, flags=re.A))
|
return error("You can only type marseys!")
|
||||||
if len(marregex) == 0: return error("You can only type marseys!")
|
|
||||||
if body:
|
|
||||||
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\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!")
|
if v.longpost and len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")
|
||||||
elif v.bird and len(body) > 140: return error("You have to type less than 140 characters!")
|
elif v.bird and len(body) > 140: return error("You have to type less than 140 characters!")
|
||||||
|
@ -1039,8 +1026,7 @@ def submit_post(v, sub=None):
|
||||||
if len(url) > 2048:
|
if len(url) > 2048:
|
||||||
return error("There's a 2048 character limit for URLs.")
|
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, flags=re.M|re.A):
|
body = image_regex.sub(r'', body)
|
||||||
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
if v and v.admin_level > 2:
|
if v and v.admin_level > 2:
|
||||||
bet_options = []
|
bet_options = []
|
||||||
|
@ -1049,12 +1035,12 @@ def submit_post(v, sub=None):
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
options = []
|
options = []
|
||||||
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body, flags=re.A):
|
for i in poll_regex.finditer(body):
|
||||||
options.append(i.group(1))
|
options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
choices = []
|
choices = []
|
||||||
for i in re.finditer('\s*&&([^\$\n]+)&&\s*', body, flags=re.A):
|
for i in choice_regex.finditer(body):
|
||||||
choices.append(i.group(1))
|
choices.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
@ -1083,8 +1069,6 @@ def submit_post(v, sub=None):
|
||||||
|
|
||||||
body_html = sanitize(body)
|
body_html = sanitize(body)
|
||||||
|
|
||||||
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 v.longpost:
|
||||||
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")
|
if len(body) < 280 or ' [](' in body or body.startswith('[]('): return error("You have to type more than 280 characters!")
|
||||||
elif v.bird:
|
elif v.bird:
|
||||||
|
@ -1213,7 +1197,7 @@ def submit_post(v, sub=None):
|
||||||
|
|
||||||
if not post.private and not post.ghost:
|
if not post.private and not post.ghost:
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(body_html, v) | NOTIFY_USERS2(title, v)
|
notify_users = NOTIFY_USERS(f'{title} {body}', v)
|
||||||
|
|
||||||
text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})"
|
text = f"@{v.username} has mentioned you: [{post.title}]({post.shortlink})"
|
||||||
if post.sub: text += f" in <a href='/s/{post.sub}'>/s/{post.sub}"
|
if post.sub: text += f" in <a href='/s/{post.sub}'>/s/{post.sub}"
|
||||||
|
|
|
@ -5,7 +5,6 @@ from flask import *
|
||||||
from files.__main__ import app
|
from files.__main__ import app
|
||||||
|
|
||||||
|
|
||||||
query_regex=re.compile("(\w+):(\S+)", flags=re.A)
|
|
||||||
valid_params=[
|
valid_params=[
|
||||||
'author',
|
'author',
|
||||||
'domain',
|
'domain',
|
||||||
|
|
|
@ -141,8 +141,7 @@ def settings_profile_post(v):
|
||||||
elif (v.patron or v.id == MOOSE_ID) and request.values.get("sig"):
|
elif (v.patron or v.id == MOOSE_ID) and request.values.get("sig"):
|
||||||
sig = request.values.get("sig")[:200]
|
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, flags=re.M|re.A):
|
sig = image_regex.sub(r'', sig)
|
||||||
if "wikipedia" not in i.group(1): sig = sig.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
sig_html = sanitize(sig)
|
sig_html = sanitize(sig)
|
||||||
bans = filter_comment_html(sig_html)
|
bans = filter_comment_html(sig_html)
|
||||||
|
@ -175,8 +174,7 @@ def settings_profile_post(v):
|
||||||
elif request.values.get("friends"):
|
elif request.values.get("friends"):
|
||||||
friends = request.values.get("friends")[:500]
|
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, flags=re.M|re.A):
|
friends = image_regex.sub(r'', friends)
|
||||||
if "wikipedia" not in i.group(1): friends = friends.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
friends_html = sanitize(friends)
|
friends_html = sanitize(friends)
|
||||||
bans = filter_comment_html(friends_html)
|
bans = filter_comment_html(friends_html)
|
||||||
|
@ -193,7 +191,7 @@ def settings_profile_post(v):
|
||||||
error="Your friends list is too long")
|
error="Your friends list is too long")
|
||||||
|
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(friends_html, v)
|
notify_users = NOTIFY_USERS(friends, v)
|
||||||
|
|
||||||
cid = notif_comment(f"@{v.username} has added you to their friends list!")
|
cid = notif_comment(f"@{v.username} has added you to their friends list!")
|
||||||
|
|
||||||
|
@ -212,8 +210,7 @@ def settings_profile_post(v):
|
||||||
elif request.values.get("enemies"):
|
elif request.values.get("enemies"):
|
||||||
enemies = request.values.get("enemies")[:500]
|
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, flags=re.M|re.A):
|
enemies = image_regex.sub(r'', enemies)
|
||||||
if "wikipedia" not in i.group(1): enemies = enemies.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
enemies_html = sanitize(enemies)
|
enemies_html = sanitize(enemies)
|
||||||
bans = filter_comment_html(enemies_html)
|
bans = filter_comment_html(enemies_html)
|
||||||
|
@ -230,7 +227,7 @@ def settings_profile_post(v):
|
||||||
error="Your enemies list is too long")
|
error="Your enemies list is too long")
|
||||||
|
|
||||||
|
|
||||||
notify_users = NOTIFY_USERS(enemies_html, v)
|
notify_users = NOTIFY_USERS(enemies, v)
|
||||||
|
|
||||||
cid = notif_comment(f"@{v.username} has added you to their enemies list!")
|
cid = notif_comment(f"@{v.username} has added you to their enemies list!")
|
||||||
|
|
||||||
|
@ -249,8 +246,7 @@ def settings_profile_post(v):
|
||||||
elif request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
|
elif request.values.get("bio") or request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
|
||||||
bio = request.values.get("bio")[:1500]
|
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, flags=re.M|re.A):
|
bio = image_regex.sub(r'', bio)
|
||||||
if "wikipedia" not in i.group(1): bio = bio.replace(i.group(1), f'})')
|
|
||||||
|
|
||||||
if request.files.get('file'):
|
if request.files.get('file'):
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
|
|
|
@ -4,7 +4,6 @@ from files.helpers.wrappers import *
|
||||||
from files.classes import *
|
from files.classes import *
|
||||||
from .front import frontlist
|
from .front import frontlist
|
||||||
|
|
||||||
valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -493,7 +493,7 @@ def message2(v, username):
|
||||||
|
|
||||||
if 'linkedin.com' in message: return {"error": "This domain 'linkedin.com' is banned."}, 403
|
if 'linkedin.com' in message: return {"error": "This domain 'linkedin.com' is banned."}, 403
|
||||||
|
|
||||||
message = re.sub('!\[\]\((.*?)\)', r'\1', message, flags=re.A)
|
message = embed_removing_regex.sub(r'\1', message)
|
||||||
|
|
||||||
text_html = sanitize(message, noimages=True)
|
text_html = sanitize(message, noimages=True)
|
||||||
|
|
||||||
|
@ -540,7 +540,7 @@ def messagereply(v):
|
||||||
|
|
||||||
if 'linkedin.com' in message: return {"error": "this domain 'linkedin.com' is banned"}
|
if 'linkedin.com' in message: return {"error": "this domain 'linkedin.com' is banned"}
|
||||||
|
|
||||||
message = re.sub('!\[\]\((.*?)\)', r'\1', message, flags=re.A)
|
message = embed_removing_regex.sub(r'\1', message)
|
||||||
|
|
||||||
id = int(request.values.get("parent_id"))
|
id = int(request.values.get("parent_id"))
|
||||||
parent = get_comment(id, v=v)
|
parent = get_comment(id, v=v)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue