regex
This commit is contained in:
parent
edc220f25d
commit
79dbfc8edd
4 changed files with 39 additions and 34 deletions
|
@ -130,6 +130,7 @@ if SITE in {'rdrama.net','devrama.xyz'}:
|
|||
AUTOCHOICE_ID = 9167
|
||||
BASEDBOT_ID = 0
|
||||
|
||||
A_ID = 1230
|
||||
MENTION_ID = 9376
|
||||
KIPPY_ID = 7150
|
||||
TAX_NOTIF_ID = 995
|
||||
|
@ -162,6 +163,7 @@ elif SITE == "pcmemes.net":
|
|||
AUTOCHOICE_ID = 2072
|
||||
BASEDBOT_ID = 800
|
||||
|
||||
A_ID = 0
|
||||
MENTION_ID = 0
|
||||
KIPPY_ID = 1592
|
||||
PIZZASHILL_ID = 0
|
||||
|
@ -194,6 +196,7 @@ else:
|
|||
AUTOCHOICE_ID = 8
|
||||
BASEDBOT_ID = 0
|
||||
|
||||
A_ID = 0
|
||||
MENTION_ID = 0
|
||||
KIPPY_ID = 0
|
||||
TAX_NOTIF_ID = 9
|
||||
|
@ -649,16 +652,18 @@ db.close()
|
|||
|
||||
if SITE_NAME == 'PCM':
|
||||
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)
|
||||
mention_regex = re.compile('(^|\s|<p>)@(([a-zA-Z0-9_\-А-я]){3,25})', flags=re.A)
|
||||
mention_regex2 = re.compile('<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)
|
||||
mention_regex = re.compile('(^|\s|<p>)@(([a-zA-Z0-9_\-]){1,25})', flags=re.A)
|
||||
mention_regex2 = re.compile('<p>@(([a-zA-Z0-9_\-]){1,25})', 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)
|
||||
image_regex = re.compile("(^https:\/\/.*\.(png|jpg|jpeg|gif|webp|maxwidth=9999|fidelity=high)($|\s))", flags=re.I|re.M|re.A)
|
||||
|
||||
valid_sub_regex = re.compile("^[a-zA-Z0-9_\-]{3,20}$", flags=re.A)
|
||||
|
||||
|
@ -676,10 +681,19 @@ based_regex = re.compile("based and (.{1,20}?)(-| )pilled", flags=re.I|re.A)
|
|||
|
||||
controversial_regex = re.compile('(/comments/.*?)"', flags=re.A)
|
||||
|
||||
spoiler_regex = re.compile('\|\|(.*?)\|\|', flags=re.A)
|
||||
video_regex = re.compile('<p><a href="(https:\/\/.*?\.(mp4|webm|mov))" rel="nofollow noopener noreferrer" target="_blank">(https:\/\/.*?\.(mp4|webm|mov))<\/a><\/p>', flags=re.I|re.A)
|
||||
unlinked_regex = re.compile('(^|\s|<p>)(https:\/\/[^ <>]*)', flags=re.A)
|
||||
imgur_regex = re.compile('(https://i\.imgur\.com/([^_]*?))\.(jpg|png|jpeg|webp)(?!</code>)', flags=re.A)
|
||||
reddit_regex = re.compile('(^|\s|<p>)\/?((r|u)\/(\w|-){3,25})', flags=re.A)
|
||||
sub_regex = re.compile('(^|\s|<p>)\/?(s\/(\w|-){3,25})', flags=re.A)
|
||||
youtube_regex = re.compile('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))</a>(?!</code>)', flags=re.A)
|
||||
strikethrough_regex = re.compile('~~(.*?)~~', 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)
|
||||
torture_regex = re.compile('(^|\s)(i|me) ', flags=re.I|re.A)
|
||||
torture_regex2 = re.compile("(^|\s)i'm ", flags=re.I|re.A)
|
||||
|
||||
def sub_matcher(match):
|
||||
return SLURS[match.group(0).lower()]
|
||||
|
|
|
@ -116,14 +116,14 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
sanitized = sanitized.replace("\ufeff", "").replace("𒐪","").replace("<script","").replace("script>","").replace('','')
|
||||
|
||||
if alert:
|
||||
for i in re.finditer("<p>@((\w|-){1,25})", sanitized, flags=re.A):
|
||||
for i in mention_regex2.finditer(sanitized):
|
||||
u = get_user(i.group(1), graceful=True)
|
||||
if u:
|
||||
sanitized = sanitized.replace(i.group(0), f'''<p><a href="/id/{u.id}"><img loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>''', 1)
|
||||
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, flags=re.A)
|
||||
sanitized = reddit_regex.sub(r'\1<a href="https://old.reddit.com/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized)
|
||||
|
||||
sanitized = re.sub('(^|\s|\n|<p>)\/?(s\/(\w|-){3,25})', r'\1<a href="/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized, flags=re.A)
|
||||
sanitized = sub_regex.sub(r'\1<a href="/\2" rel="nofollow noopener noreferrer">/\2</a>', sanitized)
|
||||
|
||||
for i in mention_regex.finditer(sanitized):
|
||||
u = get_user(i.group(2), graceful=True)
|
||||
|
@ -135,8 +135,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
sanitized = sanitized.replace(i.group(0), f'''{i.group(1)}<a href="/id/{u.id}"><img loading="lazy" src="/uid/{u.id}/pic" class="pp20">@{u.username}</a>''', 1)
|
||||
|
||||
|
||||
for i in re.finditer('https://i\.imgur\.com/(([^_]*?)\.(jpg|png|jpeg))(?!</code>)', sanitized, flags=re.A):
|
||||
sanitized = sanitized.replace(i.group(1), i.group(2) + "_d.webp?maxwidth=9999&fidelity=high")
|
||||
sanitized = imgur_regex.sub(r'\1_d.webp?maxwidth=9999&fidelity=high', sanitized)
|
||||
|
||||
if noimages:
|
||||
sanitized = bleach.Cleaner(tags=no_images,
|
||||
|
@ -181,14 +180,9 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
tag["target"] = "_blank"
|
||||
tag["rel"] = "nofollow noopener noreferrer"
|
||||
|
||||
if re.fullmatch("https?://\S+", str(tag.string), flags=re.A):
|
||||
try: tag.string = tag["href"]
|
||||
except: tag.string = ""
|
||||
|
||||
|
||||
sanitized = str(soup)
|
||||
|
||||
sanitized = re.sub('\|\|(.*?)\|\|', r'<span class="spoiler">\1</span>', sanitized)
|
||||
sanitized = spoiler_regex.sub(r'<span class="spoiler">\1</span>', sanitized)
|
||||
|
||||
if comment: marseys_used = set()
|
||||
|
||||
|
@ -265,7 +259,7 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
|
||||
if "https://youtube.com/watch?v=" in sanitized: sanitized = sanitized.replace("?t=", "&t=")
|
||||
|
||||
for i in re.finditer('" target="_blank">(https://youtube\.com/watch\?v\=(.*?))</a>(?!</code>)', sanitized, flags=re.A):
|
||||
for i in youtube_regex.finditer(sanitized):
|
||||
url = i.group(1)
|
||||
yt_id = i.group(2).split('&')[0].split('%')[0]
|
||||
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
|
||||
|
@ -280,18 +274,16 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
|||
|
||||
sanitized = sanitized.replace(replacing, htmlsource)
|
||||
|
||||
if not noimages:
|
||||
for i in re.finditer('>(https://.*?\.(mp4|webm|mov|MP4|WEBM|MOV))</a></p>', sanitized, flags=re.A):
|
||||
sanitized = sanitized.replace(f'<p><a href="{i.group(1)}" rel="nofollow noopener noreferrer" target="_blank">{i.group(1)}</a></p>', f'<p><video controls preload="none" class="embedvid"><source src="{i.group(1)}" type="video/mp4"></video>')
|
||||
for i in re.finditer('<p>(https:.*?\.(mp4|webm|mov|MP4|WEBM|MOV))</p>', sanitized, flags=re.A):
|
||||
sanitized = sanitized.replace(i.group(0), f'<p><video controls preload="none" class="embedvid"><source src="{i.group(1)}" type="video/mp4"></video>')
|
||||
|
||||
for rd in ["://reddit.com", "://new.reddit.com", "://www.reddit.com", "://redd.it", "://libredd.it"]:
|
||||
sanitized = sanitized.replace(rd, "://old.reddit.com")
|
||||
|
||||
sanitized = sanitized.replace("old.reddit.com/gallery", "reddit.com/gallery")
|
||||
sanitized = re.sub(' (https:\/\/[^ <>]*)', r' <a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a>', sanitized, flags=re.A)
|
||||
sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', sanitized, flags=re.A)
|
||||
|
||||
|
||||
sanitized = unlinked_regex.sub(r'\1<a href="\2" rel="nofollow noopener noreferrer" target="_blank">\2</a>', sanitized)
|
||||
|
||||
if not noimages:
|
||||
sanitized = video_regex.sub(r'<p><video controls preload="none" class="embedvid"><source src="\1" type="video/mp4"></video>', sanitized)
|
||||
|
||||
if comment:
|
||||
for marsey in g.db.query(Marsey).filter(Marsey.name.in_(marseys_used)).all():
|
||||
|
@ -348,7 +340,7 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
|||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
title = re.sub(f'(?<!"):{old}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{old}:" title=":{old}:" class="{classes}" src="/e/{emoji}.webp">', title, flags=re.I|re.A)
|
||||
|
||||
title = re.sub('~~(.*?)~~', r'<del>\1</del>', title, flags=re.A)
|
||||
title = strikethrough_regex.sub(r'<del>\1</del>', title)
|
||||
|
||||
signal.alarm(0)
|
||||
|
||||
|
|
|
@ -408,7 +408,7 @@ def monthly(v):
|
|||
emails = [x['email'] for x in requests.get(f'https://api.gumroad.com/v2/products/{GUMROAD_ID}/subscribers', data=data, timeout=5).json()["subscribers"]]
|
||||
|
||||
for u in g.db.query(User).filter(User.patron > 0, User.patron_utc == 0).all():
|
||||
if u.email and u.email.lower() in emails:
|
||||
if u.patron > 4 or u.email and u.email.lower() in emails:
|
||||
if u.patron == 1: procoins = 2500
|
||||
elif u.patron == 2: procoins = 5000
|
||||
elif u.patron == 3: procoins = 10000
|
||||
|
@ -419,11 +419,6 @@ def monthly(v):
|
|||
u.procoins += procoins
|
||||
g.db.add(u)
|
||||
send_repeatable_notification(u.id, f"@{v.username} has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
|
||||
elif u.patron == 5:
|
||||
procoins = 50000
|
||||
u.procoins += procoins
|
||||
g.db.add(u)
|
||||
send_repeatable_notification(u.id, f"@{v.username} has given you {procoins} Marseybux for the month of {month}! You can use them to buy awards in the [shop](/shop).")
|
||||
elif u.patron == 1 and u.admin_level > 0:
|
||||
procoins = 2500
|
||||
u.procoins += procoins
|
||||
|
@ -436,6 +431,11 @@ def monthly(v):
|
|||
u.procoins += 50000
|
||||
g.db.add(u)
|
||||
|
||||
if request.host == 'rdrama.net':
|
||||
u = g.db.query(User).filter_by(id=A_ID).one()
|
||||
u.procoins += 25000
|
||||
g.db.add(u)
|
||||
|
||||
ma = ModAction(
|
||||
kind="monthly",
|
||||
user_id=v.id
|
||||
|
|
|
@ -164,7 +164,6 @@ def front_all(v, sub=None):
|
|||
ccmode=request.values.get('ccmode', "false").lower()
|
||||
|
||||
defaultsubs = 'Include subs'
|
||||
|
||||
if v: subs=session.get('sub_toggle', defaultsubs)
|
||||
else: subs=defaultsubs
|
||||
|
||||
|
@ -270,7 +269,7 @@ def front_all(v, sub=None):
|
|||
|
||||
|
||||
@cache.memoize(timeout=86400)
|
||||
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", subs='Exclude subs', filter_words='', gt=0, lt=0, sub=None, site=None):
|
||||
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false", subs='Include subs', filter_words='', gt=0, lt=0, sub=None, site=None):
|
||||
|
||||
posts = g.db.query(Submission)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue