From 7fced29fba9828bbad185c6426b4987b158ec587 Mon Sep 17 00:00:00 2001 From: Aevann Date: Wed, 4 Oct 2023 16:05:43 +0300 Subject: [PATCH] change wholesome award to emoji award --- files/assets/css/awards.css | 42 +++++---- files/assets/js/award_modal.js | 5 ++ files/classes/award.py | 1 + files/classes/comment.py | 5 ++ files/classes/post.py | 5 ++ files/helpers/config/awards.py | 21 +---- files/routes/awards.py | 87 ++++++++++--------- files/templates/awards.html | 27 +++--- files/templates/comments.html | 6 +- files/templates/util/macros.html | 6 +- ...-change-wholesome-award-to-emoji-award.sql | 4 + 11 files changed, 122 insertions(+), 87 deletions(-) create mode 100644 migrations/20231004-change-wholesome-award-to-emoji-award.sql diff --git a/files/assets/css/awards.css b/files/assets/css/awards.css index f57e03078..1c9a96bb8 100644 --- a/files/assets/css/awards.css +++ b/files/assets/css/awards.css @@ -9,8 +9,7 @@ position: absolute; } -.stackable-container div, -.stackable-container img, .ricardo { +.stackable-container div, .stackable-container img, .ricardo { animation-iteration-count: infinite !important; animation-timing-function: linear !important; } @@ -19,7 +18,7 @@ width: min(7vw, 50px) !important; } -.wholesome img { +.emoji-award img { width: min(8vw, 60px) !important; } @@ -28,16 +27,14 @@ } +.emoji-award:nth-child(even), .emoji-award:nth-child(n+2):nth-child(n+3) img { + animation-direction: alternate-reverse; +} - -.wholesome:nth-child(even), -.wholesome:nth-child(n+2):nth-child(n+3) img -{animation-direction: alternate-reverse} - -@keyframes sealX { +@keyframes emojiX { 100% {transform: translateX(98vw)} } -@keyframes sealY { +@keyframes emojiY { 100% {transform: translateY(80vh)} } @@ -57,14 +54,27 @@ .scooter:nth-child(even) {animation-direction: reverse;} .scooter:nth-child(even) img {transform: scaleX(-1);} -.wholesome {animation: sealX 8s alternate} -.wholesome img {animation: sealY 9s alternate} -.train, .scooter {animation: train 12s;} +.emoji-award { + animation: emojiX 8s alternate; +} +.emoji-award img { + animation: emojiY 9s alternate; +} + +.train, .scooter { + animation: train 12s; +} @media (max-width: 768px) { - .wholesome {animation: sealX 6s alternate} - .wholesome img {animation: sealY 7s alternate} - .train, .scooter {animation: train 6s;} + .emoji-award { + animation: emojiX 6s alternate; + } + .emoji-award img { + animation: emojiY 7s alternate; + } + .train, .scooter { + animation: train 6s; + } } /*confetti*/ diff --git a/files/assets/js/award_modal.js b/files/assets/js/award_modal.js index c65a3ea54..14a4be074 100644 --- a/files/assets/js/award_modal.js +++ b/files/assets/js/award_modal.js @@ -137,6 +137,11 @@ function pick(kind, price, coins, marseybux) { document.getElementById('note').placeholder = "Insert new username here, or leave empty to add 1 day to the duration of the current username."; document.getElementById('note').maxLength = 25; } + else if (kind == "emoji") { + document.getElementById('notelabel').innerHTML = "Emoji name:"; + document.getElementById('note').placeholder = "Insert one site emoji here."; + document.getElementById('note').maxLength = 33; + } else { document.getElementById('notelabel').innerHTML = "Note (optional):"; document.getElementById('note').placeholder = "Note to include in award notification"; diff --git a/files/classes/award.py b/files/classes/award.py index c97ff0cf8..27f1b06b1 100644 --- a/files/classes/award.py +++ b/files/classes/award.py @@ -20,6 +20,7 @@ class AwardRelationship(Base): awarded_utc = Column(Integer) created_utc = Column(Integer) price_paid = Column(Integer, default = 0, nullable=False) + note = Column(String) user = relationship("User", primaryjoin="AwardRelationship.user_id==User.id", back_populates="awards") post = relationship("Post", primaryjoin="AwardRelationship.post_id==Post.id", back_populates="awards") diff --git a/files/classes/comment.py b/files/classes/comment.py index 3ca698b0f..ba373010c 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -314,6 +314,11 @@ class Comment(Base): def award_count(self, kind, v): return len([x for x in self.awards if x.kind == kind]) + @property + @lazy + def emoji_award_emojis(self): + return [x.note for x in self.awards if x.kind == "emoji"] + @property @lazy def json(self): diff --git a/files/classes/post.py b/files/classes/post.py index 63f5db7b3..d884e53f1 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -262,6 +262,11 @@ class Post(Base): return 4 return num + @property + @lazy + def emoji_award_emojis(self): + return [x.note for x in self.awards if x.kind == "emoji"] + @lazy def realurl(self, v): url = self.url diff --git a/files/helpers/config/awards.py b/files/helpers/config/awards.py index 720dd9de9..4b83f63ac 100644 --- a/files/helpers/config/awards.py +++ b/files/helpers/config/awards.py @@ -211,19 +211,6 @@ AWARDS = { "enabled": IS_HOMOWEEN(), "positive": True, }, - "pumpkin": { - "kind": "pumpkin", - "title": "Pumpkin", - "description": "", - "icon": "fas fa-jack-o-lantern", - "color": "text-orange", - "price": 200, - "deflectable": False, - "cosmetic": True, - "ghost": True, - "enabled": IS_HOMOWEEN(), - "positive": True, - }, "candy-corn": { "kind": "candy-corn", "title": "Candy Corn", @@ -476,10 +463,10 @@ AWARDS = { "enabled": True, "positive": True, }, - "wholesome": { - "kind": "wholesome", - "title": "Wholesome", - "description": "Summons a wholesome marsey on the post.", + "emoji": { + "kind": "emoji", + "title": "Emoji", + "description": "Summons a bouncing emoji on the post.", "icon": "fas fa-smile-beam", "color": "text-yellow", "price": 300, diff --git a/files/routes/awards.py b/files/routes/awards.py index 11943fdc8..2ab848695 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -177,7 +177,8 @@ def award_thing(v, thing_type, id): g.db.add(award) - note = request.values.get("note", "").strip() + note = request.values.get("note", "").strip()[:200] + award.note = note safe_username = f"@{thing.author_name} is" @@ -554,50 +555,56 @@ def award_thing(v, thing_type, id): if thing_type == 'comment' and (not thing.author.deflector or v == thing.author): thing.rainbowed = True g.db.add(thing) - elif kind == "spider": - if author.spider: author.spider += 86400 - else: author.spider = int(time.time()) + 86400 - badge_grant(user=author, badge_id=179, notify=False) - elif kind == "grinch": - badge_grant(badge_id=91, user=author) - elif kind == "hw-grinch": - badge_grant(badge_id=185, user=author) - elif kind == "bite": - if author.zombie < 0: - author = v + elif kind == "emoji": + award.note = award.note.strip(":").lower() + emoji = g.db.query(Emoji).filter_by(name=award.note).one_or_none() + if not emoji: + abort(404, f'an Emoji with the name "{award.note}" was not found!') + elif IS_HOMOWEEN(): + if kind == "spider": + if author.spider: author.spider += 86400 + else: author.spider = int(time.time()) + 86400 + badge_grant(user=author, badge_id=179, notify=False) + elif kind == "grinch": + badge_grant(badge_id=91, user=author) + elif kind == "hw-grinch": + badge_grant(badge_id=185, user=author) + elif kind == "bite": + if author.zombie < 0: + author = v - if author.zombie == 0: - author.zombie = -1 - badge_grant(user=author, badge_id=181) - - award_object = AwardRelationship(user_id=author.id, kind='bite') - g.db.add(award_object) - send_repeatable_notification(author.id, - "As the zombie virus washes over your mind, you feel the urge " - "to… BITE YUMMY BRAINS :marseyzombie:
" - "You receive a free **Zombie Bite** award: pass it on!") - - elif author.zombie > 0: - author.zombie -= 1 if author.zombie == 0: - send_repeatable_notification(author.id, "You are no longer **VAXXMAXXED**! Time for another booster!") + author.zombie = -1 + badge_grant(user=author, badge_id=181) - badge = author.has_badge(182) + award_object = AwardRelationship(user_id=author.id, kind='bite') + g.db.add(award_object) + send_repeatable_notification(author.id, + "As the zombie virus washes over your mind, you feel the urge " + "to… BITE YUMMY BRAINS :marseyzombie:
" + "You receive a free **Zombie Bite** award: pass it on!") + + elif author.zombie > 0: + author.zombie -= 1 + if author.zombie == 0: + send_repeatable_notification(author.id, "You are no longer **VAXXMAXXED**! Time for another booster!") + + badge = author.has_badge(182) + if badge: g.db.delete(badge) + elif kind == "vax": + if author.zombie < 0: + author.zombie = 0 + send_repeatable_notification(author.id, "You are no longer **INFECTED**! Praise Fauci!") + + badge = author.has_badge(181) if badge: g.db.delete(badge) - elif kind == "vax": - if author.zombie < 0: - author.zombie = 0 - send_repeatable_notification(author.id, "You are no longer **INFECTED**! Praise Fauci!") + elif author.zombie >= 0: + author.zombie += 2 + author.zombie = min(author.zombie, 10) - badge = author.has_badge(181) - if badge: g.db.delete(badge) - elif author.zombie >= 0: - author.zombie += 2 - author.zombie = min(author.zombie, 10) - - badge_grant(user=author, badge_id=182) - elif kind == "jumpscare": - author.jumpscare += 1 + badge_grant(user=author, badge_id=182) + elif kind == "jumpscare": + author.jumpscare += 1 if author.received_award_count: author.received_award_count += 1 diff --git a/files/templates/awards.html b/files/templates/awards.html index 8996d98ed..c19c618d5 100644 --- a/files/templates/awards.html +++ b/files/templates/awards.html @@ -1,21 +1,24 @@
{% macro stackable_award(award, src, alt) %}
- {% for i in range(p.award_count(award, v)) %} -
- {{alt}} -
- {% endfor %} + {% for i in range(p.award_count(award, v)) %} +
+ {{alt}} +
+ {% endfor %}
{% endmacro %} - {% if p.award_count("wholesome", v) %} - {% if IS_HOMOWEEN() %} - {% set wholesome = '/e/marseypumpkin.webp' %} - {% else %} - {% set wholesome = '/e/marseywholesome.webp' %} - {% endif %} - {{stackable_award('wholesome', wholesome, ':#marseywholesome:')}} + {% if p.award_count("emoji", v) %} +
+ {% for emoji in p.emoji_award_emojis %} + {% set src = '/e/' + emoji + '.webp' %} + {% set alt = ':#' + emoji + ':' %} +
+ {{alt}} +
+ {% endfor %} +
{% endif %} {% if p.award_count("train", v) %} diff --git a/files/templates/comments.html b/files/templates/comments.html index 0c74da783..d46a915f7 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -116,7 +116,11 @@ {% for a in c.awards %} - + {% if a.kind == "emoji" %} + {{a.title}} Award given by @{{a.user.username}} + {% else %} + + {% endif %} {% endfor %} {% if c.parent_post %} diff --git a/files/templates/util/macros.html b/files/templates/util/macros.html index c56b65b91..de06d0f1d 100644 --- a/files/templates/util/macros.html +++ b/files/templates/util/macros.html @@ -30,7 +30,11 @@ {% endif %} {% for a in p.awards %} - + {% if a.kind == "emoji" %} + {{a.title}} Award given by @{{a.user.username}} + {% else %} + + {% endif %} {% endfor %} {% if v and v.admin_level >= PERMS['USER_SHADOWBAN'] and p.author.shadowbanned %} diff --git a/migrations/20231004-change-wholesome-award-to-emoji-award.sql b/migrations/20231004-change-wholesome-award-to-emoji-award.sql new file mode 100644 index 000000000..beeec3039 --- /dev/null +++ b/migrations/20231004-change-wholesome-award-to-emoji-award.sql @@ -0,0 +1,4 @@ +alter table award_relationships add column note varchar(200); + +update award_relationships set kind='emoji', note='marseywholesome' where kind='wholesome'; +update award_relationships set kind='emoji', note='marseypumpkin' where kind='pumpkin';