diff --git a/files/helpers/jinja2.py b/files/helpers/jinja2.py index 16586fa77..b68cf8908 100644 --- a/files/helpers/jinja2.py +++ b/files/helpers/jinja2.py @@ -22,6 +22,15 @@ def post_embed(id, v): return render_template("submission_listing.html", listing=[p], v=v) +@app.template_filter("favorite_emojis") +def favorite_emojis(): + str = "" + emojis = session["favorite_emojis"] + emojis = sorted(emojis.items(), key=lambda x: x[1], reverse=True) + for k, v in emojis: + str += f'' + return str + @app.context_processor def inject_constants(): constants = [c for c in dir(const) if not c.startswith("_")] diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index bcfb5c691..c2e9c2924 100644 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -209,21 +209,24 @@ def sanitize(sanitized, noimages=False): start = '<s>' end = '</s>' + + if not session.get("favorite_emojis"): session["favorite_emojis"] = {} + if start in sanitized and end in sanitized and start in sanitized.split(end)[0] and end in sanitized.split(start)[1]: sanitized = sanitized.replace(start, '').replace(end, '') for i in re.finditer('

:([^ ]{1,30}?):

', sanitized): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.gif'): sanitized = sanitized.replace(f'

:{i.group(1)}:

', f'

') - # if session.get(i.group(1)): session[i.group(1)] += 1 - # else: session[i.group(1)] = 1 + if i.group(1) in session["favorite_emojis"]: session["favorite_emojis"][i.group(1)] += 1 + else: session["favorite_emojis"][i.group(1)] = 1 for i in re.finditer(':([^ ]{1,30}?):', sanitized): if path.isfile(f'./files/assets/images/emojis/{i.group(1)}.gif'): sanitized = sanitized.replace(f':{i.group(1)}:', f'') - - # if session.get(i.group(1)): session[i.group(1)] += 1 - # else: session[i.group(1)] = 1 + + if i.group(1) in session["favorite_emojis"]: session["favorite_emojis"][i.group(1)] += 1 + else: session["favorite_emojis"][i.group(1)] = 1 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.", "https://").replace("https://m.", "https://") diff --git a/files/templates/emoji_modal.html b/files/templates/emoji_modal.html index 3054e8047..21057727a 100644 --- a/files/templates/emoji_modal.html +++ b/files/templates/emoji_modal.html @@ -6,7 +6,10 @@