From c3e6b517cd8257800c0ec6b395aa9bf16f3c6e61 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 12 Feb 2022 20:38:02 +0200 Subject: [PATCH] gf --- files/helpers/sanitize.py | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 629dab803..ae88a4dc0 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -226,20 +226,24 @@ def sanitize(sanitized, noimages=False, alert=False, comment=False, edit=False): classes = 'emoji mirrored' if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' - if emoji == 'marseyrandom': emoji = random.choice(marseys) + old = emoji + if emoji == 'marseyrandom': emoji = choice(marseys) + else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - sanitized = re.sub(f'(?', sanitized, re.I) + sanitized = re.sub(f'(?', sanitized, re.I) if comment: marseys_used.add(emoji) - - elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): + else: classes = 'emoji' if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' + + old = emoji + if emoji == 'marseyrandom': emoji = choice(marseys) + else: emoji = old - if emoji == 'marseyrandom': emoji = random.choice(marseys) - - sanitized = re.sub(f'(?', sanitized, re.I) - if comment: marseys_used.add(emoji) + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): + sanitized = re.sub(f'(?', sanitized, re.I) + if comment: marseys_used.add(emoji) sanitized = sanitized.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").replace("https://www.youtube", "https://youtube") @@ -298,18 +302,23 @@ def filter_emojis_only(title, edit=False): classes = 'emoji mirrored' if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' - if emoji == 'marseyrandom': emoji = random.choice(marseys) + old = emoji + if emoji == 'marseyrandom': emoji = choice(marseys) + else: emoji = old if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): - title = re.sub(f'(?', title, re.I) + title = re.sub(f'(?', title, re.I) - elif path.isfile(f'files/assets/images/emojis/{emoji}.webp'): + else: classes = 'emoji' if not edit and random() < 0.005 and ('marsey' in emoji or emoji in marseys): classes += ' golden' - if emoji == 'marseyrandom': emoji = random.choice(marseys) + old = emoji + if emoji == 'marseyrandom': emoji = choice(marseys) + else: emoji = old - title = re.sub(f'(?', title, re.I) + if path.isfile(f'files/assets/images/emojis/{emoji}.webp'): + title = re.sub(f'(?', title, re.I) if len(title) > 1500: abort(400) else: return title \ No newline at end of file