make hat_active return a tuple

pull/83/head
Aevann 2022-12-25 00:21:49 +02:00
parent 73ab9fa4ff
commit ecfcbaf3df
11 changed files with 37 additions and 61 deletions

View File

@ -253,52 +253,28 @@ class User(Base):
if user_forced_hats: return random.choice(user_forced_hats)
else: return None
@property
@lazy
def hat_active(self):
if not FEATURES['HATS']:
return ''
def hat_active(self, v):
if FEATURES['HATS']:
if HOLIDAY_EVENT:
from files.events.helpers.const import EVENT_FORCED_HATS
if EVENT_FORCED_HATS:
return (random.choice(EVENT_FORCED_HATS), 'Merry Fistmas!')
if HOLIDAY_EVENT:
from files.events.helpers.const import EVENT_FORCED_HATS
if EVENT_FORCED_HATS: return random.choice(EVENT_FORCED_HATS)
if self.is_cakeday:
return ('/i/hats/Cakeday.webp', "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓")
if self.is_cakeday:
return '/i/hats/Cakeday.webp'
if self.age < NEW_USER_HAT_AGE:
return ('/i/new-user.webp', "Hi, I'm new here! Please be gentle :)")
if self.age < NEW_USER_HAT_AGE:
return '/i/new-user.webp'
if self.forced_hat:
return (f'/i/hats/{self.forced_hat[0]}.webp', self.forced_hat[1])
if self.forced_hat:
return f'/i/hats/{self.forced_hat[0]}.webp'
if self.equipped_hat:
return (f'/i/hats/{self.equipped_hat.name}.webp', self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v))
if self.equipped_hat:
return f'/i/hats/{self.equipped_hat.name}.webp'
return ('', '')
return ''
@lazy
def hat_tooltip(self, v):
if not FEATURES['HATS']:
return ''
if HOLIDAY_EVENT:
from files.events.helpers.const import EVENT_FORCED_HATS
if EVENT_FORCED_HATS: return 'Merry Christmas!'
if self.is_cakeday:
return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓"
if self.age < 86400 * 7:
return "Hi, I'm new here! Please be gentle :)"
if self.forced_hat:
return self.forced_hat[1]
if self.equipped_hat:
return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v)
return ''
@property
@lazy
@ -760,7 +736,7 @@ class User(Base):
'url': self.url,
'id': self.id,
'profile_url': self.profile_url,
'hat': self.hat_active,
'hat': self.hat_active(v)[0],
'bannerurl': self.banner_url,
'bio_html': self.bio_html_eager,
'coins': self.coins,

View File

@ -71,7 +71,7 @@ def speak(data, v):
"id": str(uuid.uuid4()),
"quotes": quotes,
"avatar": v.profile_url,
"hat": v.hat_active,
"hat": v.hat_active(v)[0],
"user_id": v.id,
"dm": bool(recipient and recipient != ""),
"username": v.username,

View File

@ -15,7 +15,7 @@
data-themecolor="{{v.themecolor}}"
data-namecolor="{{v.namecolor}}"
data-avatar="{{v.profile_url}}"
data-hat="{{v.hat_active}}">
data-hat="{{v.hat_active(v)[0]}}">
</div>
<script>window.global = window</script>
{% if IS_LOCALHOST %}

View File

@ -176,8 +176,8 @@
<a class="user-name text-decoration-none" href="{{c.author.url}}" data-pop-info='{{c.author.json_popover(v) | tojson}}' onclick='popclick(event)' data-bs-placement="bottom" data-bs-toggle="popover" data-bs-trigger="click" data-content-id="popover" tabindex="0" style="color:#{{c.author.name_color}}; font-size:12px; font-weight:bold;">
<div class="profile-pic-30-wrapper">
<img loading="lazy" src="{{c.author.profile_url}}" class="profile-pic-30 mr-2">
{% if c.author.hat_active -%}
<img class="profile-pic-30-hat hat" loading="lazy" src="{{c.author.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{c.author.hat_tooltip(v)}}">
{% if c.author.hat_active(v)[0] -%}
<img class="profile-pic-30-hat hat" loading="lazy" src="{{c.author.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{c.author.hat_active(v)[1]}}">
{%- endif %}
</div>
<span {% if c.author.patron and not c.distinguish_level %}class="patron" style="background-color:#{{c.author.name_color}};"{% elif c.distinguish_level %}class="mod"{% endif %}>{{c.author_name}}</span>

View File

@ -217,8 +217,8 @@
<div class="d-flex">
<div class="profile-pic-35-wrapper">
<img loading="lazy" src="{{v.profile_url}}" class="profile-pic-35">
{% if v.hat_active -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{v.hat_active}}?h=7">
{% if v.hat_active(v)[0] -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{v.hat_active(v)[0]}}?h=7">
{% elif request.path == '/hats' %}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat d-none" loading="lazy">
{%- endif %}

View File

@ -80,8 +80,8 @@
<span class="rounded">
<div class="profile-pic-35-wrapper">
<img loading="lazy" src="{{ma.user.profile_url}}" alt="avatar" class="profile-pic-35">
{% if ma.user.hat_active -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{ma.user.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{ma.user.hat_tooltip(v)}}">
{% if ma.user.hat_active(v)[0] -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{ma.user.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{ma.user.hat_active(v)[1]}}">
{%- endif %}
</div>
</span>

View File

@ -72,8 +72,8 @@
<span class="rounded">
<div class="profile-pic-35-wrapper">
<img loading="lazy" src="{{ma.user.profile_url}}" alt="avatar" class="profile-pic-35">
{% if ma.user.hat_active -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{ma.user.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{ma.user.hat_tooltip(v)}}">
{% if ma.user.hat_active(v)[0] -%}
<img id="profile-pic-35-hat" class="profile-pic-35-hat hat" loading="lazy" src="{{ma.user.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{ma.user.hat_active(v)[1]}}">
{%- endif %}
</div>
</span>

View File

@ -3,8 +3,8 @@
<a data-sort-key="{{user.username.lower()}}" style="color:#{{user.name_color}};font-weight:bold" href="/@{{user.username}}">
<div class="profile-pic-20-wrapper mb-2">
<img loading="lazy" src="{{user.profile_url}}" class="pp20">
{% if user.hat_active -%}
<img class="profile-pic-20-hat hat" loading="lazy" src="{{user.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{user.hat_tooltip(v)}}">
{% if user.hat_active(v)[0] -%}
<img class="profile-pic-20-hat hat" loading="lazy" src="{{user.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{user.hat_active(v)[1]}}">
{%- endif %}
</div>
<span {% if user.patron %}class="patron" style="background-color:#{{user.name_color}}"{% endif %}>{{user.user_name}}</span>

View File

@ -5,8 +5,8 @@
<img loading="lazy" src="{{u.banner_url}}" class="card-img-top" alt="@{{u.username}} user banner" height=175 style="object-fit: cover">
<div class="profile-pic-50-wrapper" style="position: absolute; left: 15px; bottom: 15px; box-sizing: content-box;">
<img loading="lazy" src="{{u.profile_url}}" class="profile-pic-50">
{% if u.hat_active -%}
<img id="profile-pic-50-hat" class="profile-pic-50-hat hat" loading="lazy" src="{{u.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.hat_tooltip(v)}}">
{% if u.hat_active(v)[0] -%}
<img id="profile-pic-50-hat" class="profile-pic-50-hat hat" loading="lazy" src="{{u.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.hat_active(v)[1]}}">
{%- endif %}
</div>
</div>

View File

@ -9,11 +9,11 @@
<div class="w-100 my-3">
<div class="container-fluid nobackground">
<div class="d-md-flex text-center text-md-left">
<div id="profile--pfp" {% if u.hat_active %}class="profile--pfp--hat hat"{% endif %}>
<div id="profile--pfp" {% if u.hat_active(v)[0] %}class="profile--pfp--hat hat"{% endif %}>
<a rel="nofollow noopener" href="{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}" class="profile-pic-100-wrapper">
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" loading="lazy" src="{{u.profile_url}}" class="profile-pic profile-pic-100 mb-5">
{% if u.hat_active -%}
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" class="profile-pic-100-hat hat" loading="lazy" src="{{u.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.hat_tooltip(v)}}">
{% if u.hat_active(v)[0] -%}
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" class="profile-pic-100-hat hat" loading="lazy" src="{{u.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{u.hat_active(v)[1]}}">
{%- endif %}
</a>
</div>
@ -270,8 +270,8 @@
<div style="margin-top: -34px;" id="profile-mobile--pfp">
<a rel="nofollow noopener" href="{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}" class="profile-pic-65-wrapper">
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" loading="lazy" src="{{u.profile_url}}" class="profile-pic-65 bg-white mb-2">
{% if u.hat_active -%}
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" class="profile-pic-65-hat hat" loading="lazy" src="{{u.hat_active}}?h=7">
{% if u.hat_active(v)[0] -%}
<img onclick="expandDesktopImage('{% if u.highres %}{{u.highres}}{% else %}{{u.profile_url}}{% endif %}')" class="profile-pic-65-hat hat" loading="lazy" src="{{u.hat_active(v)[0]}}?h=7">
{%- endif %}
</a>
</div>

View File

@ -87,8 +87,8 @@
<a class="user-name text-decoration-none" href="{{p.author.url}}" data-pop-info='{{p.author.json_popover(v) | tojson}}' onclick='popclick(event)' data-bs-placement="bottom" data-bs-toggle="popover" data-bs-trigger="click" data-content-id="popover" tabindex="0" style="color: #{{p.author.name_color}}; font-weight: bold;">
<div class="profile-pic-30-wrapper" style="margin-top:9px">
<img loading="lazy" src="{{p.author.profile_url}}" class="profile-pic-30 mr-2">
{% if p.author.hat_active -%}
<img class="profile-pic-30-hat hat" loading="lazy" src="{{p.author.hat_active}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{p.author.hat_tooltip(v)}}">
{% if p.author.hat_active(v)[0] -%}
<img class="profile-pic-30-hat hat" loading="lazy" src="{{p.author.hat_active(v)[0]}}?h=7" data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{p.author.hat_active(v)[1]}}">
{%- endif %}
</div>
<span {% if p.author.patron and not p.distinguish_level %}class="patron" style="background-color:#{{p.author.name_color}};"{% elif p.distinguish_level %}class="mod"{% endif %}>{{p.author_name}}</span>