bb
This commit is contained in:
parent
1700c4717d
commit
2112fe604a
2 changed files with 12 additions and 12 deletions
|
@ -99,7 +99,7 @@ allowed_protocols = ['http', 'https']
|
|||
|
||||
allowed_styles = ['color', 'background-color', 'font-weight', 'transform', '-webkit-transform']
|
||||
|
||||
def sanitize(sanitized, noimages=False, alert=False):
|
||||
def sanitize(sanitized, noimages=False, alert=False, comment=False):
|
||||
|
||||
sanitized = markdown(sanitized)
|
||||
|
||||
|
@ -186,10 +186,10 @@ def sanitize(sanitized, noimages=False, alert=False):
|
|||
|
||||
sanitized = re.sub('\|\|(.*?)\|\|', r'<span class="spoiler">\1</span>', sanitized)
|
||||
|
||||
with open("marsey_count.json", 'r') as f:
|
||||
marsey_count = loads(f.read())
|
||||
|
||||
if comment:
|
||||
with open("marsey_count.json", 'r') as f: marsey_count = loads(f.read())
|
||||
marseys_used = set()
|
||||
|
||||
for i in re.finditer("[^a]>\s*(:[!#]{0,2}\w+:\s*)+<\/", sanitized):
|
||||
old = i.group(0)
|
||||
if 'marseylong1' in old or 'marseylong2' in old or 'marseyllama1' in old or 'marseyllama2' in old: new = old.lower().replace(">", " class='mb-0'>")
|
||||
|
@ -211,7 +211,7 @@ def sanitize(sanitized, noimages=False, alert=False):
|
|||
|
||||
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}:" delay="0" {classes}src="/static/assets/images/emojis/{remoji}.webp" >', new, flags=re.I)
|
||||
marseys_used.add(emoji)
|
||||
if comment: marseys_used.add(emoji)
|
||||
|
||||
sanitized = sanitized.replace(old, new)
|
||||
|
||||
|
@ -222,11 +222,11 @@ def sanitize(sanitized, noimages=False, alert=False):
|
|||
emoji = emoji[1:]
|
||||
if path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
sanitized = re.sub(f'(?<!"):!{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":!{emoji}:" title=":!{emoji}:" delay="0" class="emoji mirrored" src="/static/assets/images/emojis/{emoji}.webp">', sanitized, flags=re.I)
|
||||
marseys_used.add(emoji)
|
||||
if comment: marseys_used.add(emoji)
|
||||
|
||||
elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'):
|
||||
sanitized = re.sub(f'(?<!"):{emoji}:', f'<img loading="lazy" data-bs-toggle="tooltip" alt=":{emoji}:" title=":{emoji}:" delay="0" class="emoji" src="/static/assets/images/emojis/{emoji}.webp">', sanitized, flags=re.I)
|
||||
marseys_used.add(emoji)
|
||||
if comment: marseys_used.add(emoji)
|
||||
|
||||
sanitized = sanitized.replace("https://www.", "https://").replace("https://youtu.be/", "https://youtube.com/watch?v=").replace("https://music.youtube.com/watch?v=", "https://youtube.com/watch?v=").replace("https://open.spotify.com/", "https://open.spotify.com/embed/").replace("https://streamable.com/", "https://streamable.com/e/").replace("https://youtube.com/shorts/", "https://youtube.com/watch?v=").replace("https://mobile.twitter", "https://twitter").replace("https://m.facebook", "https://facebook").replace("m.wikipedia.org", "wikipedia.org").replace("https://m.youtube", "https://youtube")
|
||||
|
||||
|
@ -258,9 +258,9 @@ def sanitize(sanitized, noimages=False, alert=False):
|
|||
sanitized = re.sub(' (https:\/\/[^ <>]*)', r' <a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a>', sanitized)
|
||||
sanitized = re.sub('<p>(https:\/\/[^ <>]*)', r'<p><a target="_blank" rel="nofollow noopener noreferrer" href="\1">\1</a></p>', sanitized)
|
||||
|
||||
if comment:
|
||||
for emoji in marseys_used:
|
||||
if emoji in marsey_count: marsey_count[emoji] += 1
|
||||
|
||||
with open('marsey_count.json', 'w') as f: dump(marsey_count, f)
|
||||
|
||||
return sanitized
|
||||
|
|
|
@ -211,7 +211,7 @@ def api_comment(v):
|
|||
|
||||
if v.agendaposter and not v.marseyawarded: body = torture_ap(body, v.username)
|
||||
|
||||
body_html = sanitize(body)
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue