From b3a56ca16827e8389e7369a93060f68a9145893c Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 5 Sep 2022 06:33:08 +0200 Subject: [PATCH] more hat shit --- files/assets/js/chat.js | 2 +- .../assets/js/comments+submission_listing.js | 2 +- files/classes/user.py | 19 +++++++++++++------ files/routes/chat.py | 2 +- files/templates/chat.html | 4 ++-- files/templates/comments.html | 2 +- files/templates/hats.html | 4 ++-- files/templates/header.html | 2 +- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- files/templates/user_in_table.html | 2 +- files/templates/userpage.html | 4 ++-- files/templates/util/assetcache.html | 2 +- 13 files changed, 28 insertions(+), 21 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index 58a4595764..f133ce59cb 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -80,7 +80,7 @@ socket.on('speak', function(json) { document.getElementsByClassName('userlink')[0].classList.remove('d-none') document.getElementsByClassName('avatar')[0].classList.remove('d-none') document.getElementsByClassName('avatar-pic')[0].src = json['avatar'] - if (json['hat']) document.getElementsByClassName('avatar-hat')[0].src = `/i/hats/${json['hat']}.webp?v=3` + if (json['hat']) document.getElementsByClassName('avatar-hat')[0].src = json['hat']} + '?v=3' document.getElementsByClassName('userlink')[0].href = '/@' + json['username'] document.getElementsByClassName('userlink')[0].style.color = '#' + json['namecolor'] document.getElementsByClassName('time')[0].classList.remove('d-none') diff --git a/files/assets/js/comments+submission_listing.js b/files/assets/js/comments+submission_listing.js index c08cb7251c..7586038eaf 100644 --- a/files/assets/js/comments+submission_listing.js +++ b/files/assets/js/comments+submission_listing.js @@ -49,7 +49,7 @@ function popclick(e) { popover.getElementsByClassName('pop-banner')[0].src = author["bannerurl"] popover.getElementsByClassName('pop-picture')[0].src = author["profile_url"] - if (author["hat"]) popover.getElementsByClassName('pop-hat')[0].src = `/i/hats/${author['hat']}.webp?v=3` + if (author["hat"]) popover.getElementsByClassName('pop-hat')[0].src = author['hat'] + '?v=3' popover.getElementsByClassName('pop-username')[0].innerHTML = author["username"] if (popover.getElementsByClassName('pop-bio').length > 0) { popover.getElementsByClassName('pop-bio')[0].innerHTML = author["bio_html"] diff --git a/files/classes/user.py b/files/classes/user.py index 71a32ee792..382ec8fd7b 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -192,6 +192,13 @@ class User(Base): def equipped_hat_ids(self): return [x.hat_id for x in self.equipped_hats] + @property + @lazy + def equipped_hat(self): + if self.equipped_hats: + return random.choice(self.equipped_hats) + return None + @property @lazy def hat_active(self): @@ -199,10 +206,10 @@ class User(Base): return '' if self.is_cakeday: - return 'Cakeday.webp' + return '/i/hats/Cakeday.webp' - if self.equipped_hats: - return random.choice(self.equipped_hats) + if self.equipped_hat: + return f'/i/hats/{self.equipped_hat.name}.webp' return '' @@ -214,8 +221,8 @@ class User(Base): if self.is_cakeday: return "I've spent another year rotting my brain with dramaposting, please ridicule me 🤓" - if self.equipped_hats: - return self.hat_active.name + ' - ' + self.hat_active.censored_description(v) + if self.equipped_hat: + return self.equipped_hat.name + ' - ' + self.equipped_hat.censored_description(v) return '' @@ -693,7 +700,7 @@ class User(Base): 'url': self.url, 'id': self.id, 'profile_url': self.profile_url, - 'hat': self.hat_active.name, + 'hat': self.hat_active, 'bannerurl': self.banner_url, 'bio_html': self.bio_html_eager, 'coins': self.coins, diff --git a/files/routes/chat.py b/files/routes/chat.py index fe810f5075..307b33eb3f 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -66,7 +66,7 @@ def speak(data, v): data={ "avatar": v.profile_url, - "hat": v.hat_active.name, + "hat": v.hat_active, "username": v.username, "namecolor": v.namecolor, "text": text, diff --git a/files/templates/chat.html b/files/templates/chat.html index 15efbf817d..ba095d38a5 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -169,7 +169,7 @@
{% if m.get('hat') -%} - + {%- endif %}
{% endif %} @@ -222,6 +222,6 @@ - + \ No newline at end of file diff --git a/files/templates/comments.html b/files/templates/comments.html index abe93a548d..63917473ca 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -171,7 +171,7 @@
{% if c.author.hat_active -%} - + {%- endif %}
{{c.author_name}} diff --git a/files/templates/hats.html b/files/templates/hats.html index 0dfda2157c..6184e5867a 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -22,7 +22,7 @@ const profile_pic_hat = document.getElementById("profile-pic-35-hat"); function extra_actions(xhr) { if(xhr.status == 200) { - profile_pic_hat.src = `/i/hats/${hat_name}.webp?v=3` + profile_pic_hat.src = `${hat_name}.webp?v=3` profile_pic_hat.classList.remove('d-none') } } @@ -55,7 +55,7 @@ {% for hat, user in hats %} - {{hat.name}} + {{hat.name}} {{hat.name}} {{hat.censored_description(v)}} {% if SITE == 'rdrama.net' %} diff --git a/files/templates/header.html b/files/templates/header.html index 52457b6424..eb7556612c 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -207,7 +207,7 @@
{% if v.hat_active -%} - + {% elif request.path == '/hats' %} {%- endif %} diff --git a/files/templates/submission.html b/files/templates/submission.html index 933da33360..41548219f7 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -677,7 +677,7 @@
{% if p.author.hat_active -%} - + {%- endif %}
{{p.author_name}} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 03014d99f6..bce842ddc1 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -172,7 +172,7 @@
{% if p.author.hat_active -%} - + {%- endif %}
{{p.author_name}} diff --git a/files/templates/user_in_table.html b/files/templates/user_in_table.html index 563ded4182..1ac130dc99 100644 --- a/files/templates/user_in_table.html +++ b/files/templates/user_in_table.html @@ -2,7 +2,7 @@
{% if user.hat_active -%} - + {%- endif %}
{{user.username}} diff --git a/files/templates/userpage.html b/files/templates/userpage.html index fd816e9029..77e48dc524 100644 --- a/files/templates/userpage.html +++ b/files/templates/userpage.html @@ -42,7 +42,7 @@ {% if u.hat_active -%} - + {%- endif %}
@@ -407,7 +407,7 @@ {% if u.hat_active -%} - + {%- endif %} diff --git a/files/templates/util/assetcache.html b/files/templates/util/assetcache.html index e7ff991f3c..51c2d0b6fd 100644 --- a/files/templates/util/assetcache.html +++ b/files/templates/util/assetcache.html @@ -18,7 +18,7 @@ set CACHE_VER = { 'js/award_modal.js': 4000, 'js/bootstrap.js': 4000, 'js/category_modal.js': 4000, - 'js/comments+submission_listing.js': 4001, + 'js/comments+submission_listing.js': 4002, 'js/comments_admin.js': 4000, 'js/comments_v.js': 4000, 'js/submission_listing.js': 4000,