convert /marseys into /emojis

master
Aevann 2023-07-05 00:40:00 +03:00
parent 225c63af0b
commit fcb74c7c9b
6 changed files with 34 additions and 40 deletions

View File

@ -557,7 +557,6 @@ PERMS = { # Minimum admin_level to perform action.
}
FEATURES = {
'MARSEYS': True,
'MARSEYBUX': True,
'AWARDS': True,
'CHAT': True,

View File

@ -184,8 +184,7 @@ def approve_emoji(v, name):
cache.delete("emojis")
if emoji.kind == "Marsey":
cache.delete("marseys")
cache.delete("emoji_list")
purge_files_in_cache(f"https://{SITE}/e/{emoji.name}/webp")
@ -494,8 +493,7 @@ def update_emoji(v):
g.db.add(ma)
cache.delete("emojis")
if existing.kind == "Marsey":
cache.delete("marseys")
cache.delete("emoji_list")
return render_template("admin/update_assets.html", v=v, msg=f"'{name}' updated successfully!", name=name, tags=tags, kind=kind, type="Emoji")

View File

@ -41,33 +41,29 @@ def reddit_post(subreddit, v, path):
return redirect(f'https://{reddit}/{post_id}')
@cache.cached(key_prefix="marseys")
def get_marseys():
if not FEATURES['MARSEYS']: return []
marseys = []
for marsey, author in g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.kind == "Marsey", Emoji.submitter_id == None).order_by(Emoji.count.desc()):
marsey.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None
marseys.append(marsey)
return marseys
@cache.cached(key_prefix="emoji_list")
def get_emoji_list():
emojis = []
for emoji, author in g.db.query(Emoji, User).join(User, Emoji.author_id == User.id).filter(Emoji.submitter_id == None).order_by(Emoji.count.desc()):
emoji.author = author.username if FEATURES['ASSET_SUBMISSIONS'] else None
emojis.append(emoji)
return emojis
@app.get("/marseys")
@app.get("/emojis")
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_desired_with_logingate
def marseys(v:User):
if SITE_NAME != 'rDrama':
abort(404)
marseys = get_marseys()
authors = get_accounts_dict([m.author_id for m in marseys], v=v, graceful=True)
@auth_required
def emoji_list(v:User):
emojis = get_emoji_list()
authors = get_accounts_dict([e.author_id for e in emojis], v=v, graceful=True)
original = os.listdir("/asset_submissions/emojis/original")
for marsey in marseys:
marsey.user = authors.get(marsey.author_id)
for emoji in emojis:
emoji.user = authors.get(emoji.author_id)
for x in IMAGE_FORMATS:
if f'{marsey.name}.{x}' in original:
marsey.og = f'{marsey.name}.{x}'
if f'{emoji.name}.{x}' in original:
emoji.og = f'{emoji.name}.{x}'
break
return render_template("marseys.html", v=v, marseys=marseys)
return render_template("emojis.html", v=v, emojis=emojis)
@ -91,7 +87,7 @@ def get_emojis():
@limiter.limit(DEFAULT_RATELIMIT)
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
@auth_required
def emoji_list(v):
def emojis(v):
return get_emojis()

View File

@ -1,13 +1,13 @@
{% extends "default.html" %}
{% block pagetitle %}Marseys{% endblock %}
{% block pagetype %}marseys{% endblock %}
{% block pagetitle %}Emojis{% endblock %}
{% block pagetype %}emojis{% endblock %}
{% block content %}
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>Name</th>
<th>Marsey</th>
<th>Emoji</th>
<th>Usage</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th>Author</th>
@ -18,22 +18,22 @@
{% endif %}
</tr>
</thead>
<tbody id="marseys-table">
{% for marsey in marseys %}
<tbody id="emojis-table">
{% for emoji in emojis %}
<tr>
<td>{{loop.index}}</td>
<td>{{marsey.name}}</td>
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
<td>{{marsey.count}}</td>
<td>{{emoji.name}}</td>
<td><img class="emoji" loading="lazy" data-bs-toggle="tooltip" alt=":#{{emoji.name}}:" title=":{{emoji.name}}:" src="/e/{{emoji.name}}.webp"></td>
<td>{{emoji.count}}</td>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
{% set user = marsey.user %}
{% set user = emoji.user %}
<td>{% include "user_in_table.html" %}</td>
{% endif %}
<td data-sort-key="{{marsey.created_utc or 0}}" {% if marsey.created_utc != None %}data-time="{{marsey.created_utc}}"{% endif %}></td>
<td data-sort-key="{{emoji.created_utc or 0}}" {% if emoji.created_utc != None %}data-time="{{emoji.created_utc}}"{% endif %}></td>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<td>
{% if marsey.og %}
<a href="{{SITE_FULL_IMAGES}}/asset_submissions/emojis/original/{{marsey.og}}">{{marsey.og}}</a>
{% if emoji.og %}
<a href="{{SITE_FULL_IMAGES}}/asset_submissions/emojis/original/{{emoji.og}}">{{emoji.og}}</a>
{% endif %}
</td>
{% endif %}

View File

@ -22,6 +22,7 @@
<p class="text-center text-md mb-4">
<a class="sidebar-link d-md-none" href="/random_user" data-bs-toggle="tooltip" data-bs-placement="top" title="Random User with a Profile Anthem"><i class="fas fa-music"></i></a>
<a class="sidebar-link" href="/emojis" data-bs-toggle="tooltip" data-bs-placement="top" title="Emojis"><i class="fas fa-cat"></i></a>
<a class="sidebar-link" href="/badges" data-bs-toggle="tooltip" data-bs-placement="top" title="Badges"><i class="fas fa-hexagon"></i></a>
<a class="sidebar-link" href="/admins" data-bs-toggle="tooltip" data-bs-placement="top" title="Admins"><i class="fas fa-crown"></i></a>
<a class="sidebar-link" href="/log" data-bs-toggle="tooltip" data-bs-placement="top" title="Moderation Log"><i class="fas fa-scroll-old"></i></a>

View File

@ -28,7 +28,7 @@
<p class="text-center text-md mb-4">
<a class="sidebar-link d-md-none" href="/random_user" data-bs-toggle="tooltip" data-bs-placement="top" title="Random User with a Profile Anthem"><i class="fas fa-music"></i></a>
<a class="sidebar-link" href="/marseys" data-bs-toggle="tooltip" data-bs-placement="top" title="Marseys"><i class="fas fa-cat"></i></a>
<a class="sidebar-link" href="/emojis" data-bs-toggle="tooltip" data-bs-placement="top" title="Emojis"><i class="fas fa-cat"></i></a>
<a class="sidebar-link" href="/badges" data-bs-toggle="tooltip" data-bs-placement="top" title="Badges"><i class="fas fa-hexagon"></i></a>
<a class="sidebar-link" href="/admins" data-bs-toggle="tooltip" data-bs-placement="top" title="Admins"><i class="fas fa-crown"></i></a>
<a class="sidebar-link" href="/log" data-bs-toggle="tooltip" data-bs-placement="top" title="Moderation Log"><i class="fas fa-scroll-old"></i></a>