marregex
This commit is contained in:
parent
ca41388f41
commit
7679ed2bfd
4 changed files with 22 additions and 24 deletions
File diff suppressed because one or more lines are too long
|
@ -11,10 +11,6 @@ from random import random, choice
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
|
|
||||||
db = db_session()
|
|
||||||
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',
|
allowed_tags = tags = ['b',
|
||||||
'blockquote',
|
'blockquote',
|
||||||
'br',
|
'br',
|
||||||
|
@ -222,9 +218,9 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
classes = 'emoji-md'
|
classes = 'emoji-md'
|
||||||
remoji = emoji
|
remoji = emoji
|
||||||
|
|
||||||
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden'
|
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden'
|
||||||
|
|
||||||
if remoji == 'marseyrandom': remoji = choice(marseys)
|
if remoji == 'marseyrandom': remoji = choice(marseys_const)
|
||||||
|
|
||||||
if path.isfile(f'files/assets/images/emojis/{remoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{remoji}.webp'):
|
||||||
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp" >', new, flags=re.I)
|
new = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" class="{classes}" src="/e/{remoji}.webp" >', new, flags=re.I)
|
||||||
|
@ -244,10 +240,10 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
if emoji.startswith("!"):
|
if emoji.startswith("!"):
|
||||||
emoji = emoji[1:]
|
emoji = emoji[1:]
|
||||||
classes = 'emoji mirrored'
|
classes = 'emoji mirrored'
|
||||||
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden'
|
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden'
|
||||||
|
|
||||||
old = emoji
|
old = emoji
|
||||||
if emoji == 'marseyrandom': emoji = choice(marseys)
|
if emoji == 'marseyrandom': emoji = choice(marseys_const)
|
||||||
else: emoji = old
|
else: emoji = old
|
||||||
|
|
||||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||||
|
@ -255,10 +251,10 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False):
|
||||||
if comment: marseys_used.add(emoji)
|
if comment: marseys_used.add(emoji)
|
||||||
else:
|
else:
|
||||||
classes = 'emoji'
|
classes = 'emoji'
|
||||||
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden'
|
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden'
|
||||||
|
|
||||||
old = emoji
|
old = emoji
|
||||||
if emoji == 'marseyrandom': emoji = choice(marseys)
|
if emoji == 'marseyrandom': emoji = choice(marseys_const)
|
||||||
else: emoji = old
|
else: emoji = old
|
||||||
|
|
||||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||||
|
@ -332,10 +328,10 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
||||||
if emoji.startswith("!"):
|
if emoji.startswith("!"):
|
||||||
emoji = emoji[1:]
|
emoji = emoji[1:]
|
||||||
classes = 'emoji mirrored'
|
classes = 'emoji mirrored'
|
||||||
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden'
|
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden'
|
||||||
|
|
||||||
old = emoji
|
old = emoji
|
||||||
if emoji == 'marseyrandom': emoji = choice(marseys)
|
if emoji == 'marseyrandom': emoji = choice(marseys_const)
|
||||||
else: emoji = old
|
else: emoji = old
|
||||||
|
|
||||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||||
|
@ -343,10 +339,10 @@ def filter_emojis_only(title, edit=False, graceful=False):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
classes = 'emoji'
|
classes = 'emoji'
|
||||||
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden'
|
if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys_const): classes += ' golden'
|
||||||
|
|
||||||
old = emoji
|
old = emoji
|
||||||
if emoji == 'marseyrandom': emoji = choice(marseys)
|
if emoji == 'marseyrandom': emoji = choice(marseys_const)
|
||||||
else: emoji = old
|
else: emoji = old
|
||||||
|
|
||||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||||
|
|
|
@ -209,7 +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("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A))
|
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 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
|
||||||
|
@ -717,7 +717,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, flags=re.A))
|
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 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
|
||||||
|
|
|
@ -20,9 +20,7 @@ import requests
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
|
||||||
db = db_session()
|
marseys = [f':#{x[0]}:' for x in marseys_const]
|
||||||
marseys = [f':#{x[0]}:' for x in db.query(Marsey.name).all()]
|
|
||||||
db.close()
|
|
||||||
|
|
||||||
if path.exists(f'snappy_{SITE_NAME}.txt'):
|
if path.exists(f'snappy_{SITE_NAME}.txt'):
|
||||||
with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f:
|
with open(f'snappy_{SITE_NAME}.txt', "r", encoding="utf-8") as f:
|
||||||
|
@ -463,10 +461,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, flags=re.A))
|
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\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, flags=re.A))
|
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 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
|
||||||
|
@ -972,10 +970,10 @@ def submit_post(v, sub=None):
|
||||||
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:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", title, flags=re.A))
|
marregex = list(re.finditer("^(:[!#A-Za-z0-9]{1,30}?:\s*)+$", title, flags=re.A))
|
||||||
if len(marregex) == 0: return error("You can only type marseys!")
|
if len(marregex) == 0: return error("You can only type marseys!")
|
||||||
if body:
|
if body:
|
||||||
marregex = list(re.finditer("^(:[!#]{0,2}m\w+:\s*)+$", body, flags=re.A))
|
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 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!")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue