regex2
This commit is contained in:
parent
b1f996f0b6
commit
2a7d04ea0a
4 changed files with 9 additions and 21 deletions
|
@ -341,7 +341,7 @@ class Comment(Base):
|
||||||
if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
|
if v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
|
||||||
|
|
||||||
if v and v.controversial:
|
if v and v.controversial:
|
||||||
for i in re.finditer('(/comments/.*?)"', body, flags=re.A):
|
for i in controversial_regex.finditer(body):
|
||||||
url = i.group(1)
|
url = i.group(1)
|
||||||
p = urlparse(url).query
|
p = urlparse(url).query
|
||||||
p = parse_qs(p)
|
p = parse_qs(p)
|
||||||
|
@ -395,24 +395,7 @@ class Comment(Base):
|
||||||
|
|
||||||
if not body: return ""
|
if not body: return ""
|
||||||
|
|
||||||
body = censor_slurs(body, v)
|
return censor_slurs(body, v)
|
||||||
|
|
||||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
|
||||||
|
|
||||||
if v and v.nitter and not '/i/' in body: body = body.replace("www.twitter.com", "nitter.net").replace("twitter.com", "nitter.net")
|
|
||||||
|
|
||||||
if v and v.controversial:
|
|
||||||
for i in re.finditer('(/comments/.*?)"', body, flags=re.A):
|
|
||||||
url = i.group(1)
|
|
||||||
p = urlparse(url).query
|
|
||||||
p = parse_qs(p)
|
|
||||||
|
|
||||||
if 'sort' not in p: p['sort'] = ['controversial']
|
|
||||||
|
|
||||||
url_noquery = url.split('?')[0]
|
|
||||||
body = body.replace(url, f"{url_noquery}?{urlencode(p, True)}")
|
|
||||||
|
|
||||||
return body
|
|
||||||
|
|
||||||
def print(self):
|
def print(self):
|
||||||
print(f'post: {self.id}, comment: {self.author_id}', flush=True)
|
print(f'post: {self.id}, comment: {self.author_id}', flush=True)
|
||||||
|
|
|
@ -665,12 +665,17 @@ valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A)
|
||||||
query_regex = re.compile("(\w+):(\S+)", flags=re.A)
|
query_regex = re.compile("(\w+):(\S+)", flags=re.A)
|
||||||
|
|
||||||
poll_regex = re.compile("\s*\$\$([^\$\n]+)\$\$\s*", flags=re.A)
|
poll_regex = re.compile("\s*\$\$([^\$\n]+)\$\$\s*", flags=re.A)
|
||||||
|
bet_regex = re.compile("\s*\$\$\$([^\$\n]+)\$\$\$\s*", flags=re.A)
|
||||||
choice_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)
|
embed_removing_regex = re.compile('!\[\]\((.*?)\)', flags=re.A)
|
||||||
|
|
||||||
title_regex = re.compile("[^\w ]", flags=re.A)
|
title_regex = re.compile("[^\w ]", flags=re.A)
|
||||||
|
|
||||||
|
based_regex = re.compile("based and (.{1,20}?)(-| )pilled", flags=re.I|re.A)
|
||||||
|
|
||||||
|
controversial_regex = re.compile('(/comments/.*?)"', flags=re.A)
|
||||||
|
|
||||||
slur_regex = re.compile(rf"((?<=\s|>)|^)({single_words})((?=[\s<,.$]|s[\s<,.$]))", flags=re.I|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)
|
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_regex = re.compile('(^|\s|\n)(i|me) ', flags=re.I|re.A)
|
||||||
|
|
|
@ -413,7 +413,7 @@ def api_comment(v):
|
||||||
g.db.add(c_choice)
|
g.db.add(c_choice)
|
||||||
|
|
||||||
if request.host == 'pcmemes.net' and c.body.lower().startswith("based"):
|
if request.host == 'pcmemes.net' and c.body.lower().startswith("based"):
|
||||||
pill = re.match("based and (.{1,20}?)(-| )pilled", body, flags=re.I|re.A)
|
pill = based_regex.match(body)
|
||||||
|
|
||||||
if level == 1: basedguy = get_account(parent_post.author_id)
|
if level == 1: basedguy = get_account(parent_post.author_id)
|
||||||
else: basedguy = get_account(c.parent_comment.author_id)
|
else: basedguy = get_account(c.parent_comment.author_id)
|
||||||
|
|
|
@ -1030,7 +1030,7 @@ def submit_post(v, sub=None):
|
||||||
|
|
||||||
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, flags=re.A):
|
for i in bet_regex.finditer(body):
|
||||||
bet_options.append(i.group(1))
|
bet_options.append(i.group(1))
|
||||||
body = body.replace(i.group(0), "")
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue