From 7729fcb3240cd1f75b1c2dd0764f21ca22cec121 Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 12 Apr 2024 14:05:01 +0200 Subject: [PATCH] make april fools code permanent and test it on staging --- files/classes/comment.py | 2 +- files/classes/post.py | 2 +- files/classes/user.py | 11 +++- files/helpers/config/const.py | 5 ++ files/templates/comments.html | 86 ++++++++++++++++---------------- files/templates/util/macros.html | 32 ++++++------ 6 files changed, 76 insertions(+), 62 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index c87830e99..ff8e60b9d 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -341,7 +341,7 @@ class Comment(Base): @lazy def author_name(self): if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻' - return self.author.user_name + return self.author.switched.user_name @property @lazy diff --git a/files/classes/post.py b/files/classes/post.py index 496b8fac5..a3df8224a 100644 --- a/files/classes/post.py +++ b/files/classes/post.py @@ -172,7 +172,7 @@ class Post(Base): @lazy def author_name(self): if self.ghost and not (hasattr(g, 'v') and g.v and self.id == g.v.id): return '👻' - return self.author.user_name + return self.author.switched.user_name @property @lazy diff --git a/files/classes/user.py b/files/classes/user.py index 12c79393d..d070a94fd 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -8,7 +8,7 @@ from sqlalchemy.sql import case, func, literal from sqlalchemy.sql.expression import not_, and_, or_ from sqlalchemy.sql.sqltypes import * from sqlalchemy.exc import OperationalError -from flask import g, session, request +from flask import g, session, request, has_request_context from files.classes import Base from files.classes.casino_game import CasinoGame @@ -1325,6 +1325,15 @@ class User(Base): return f'((({self.username})))' return self.username + @property + @lazy + def switched(self): + if not IS_FOOL() or (has_request_context() and request.path in {'/notifications/modmail', '/notifications/messages'}): + return self + + three_days = time.time() - 259200 + return g.db.query(User).filter(User.truescore < self.truescore, User.last_active > three_days).order_by(User.truescore.desc()).first() or self + @property @lazy def unmutable(self): diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 324835af4..4bbb08267 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -1070,6 +1070,11 @@ fourth_end = datetime.datetime.strptime(f'5/7/{t.year}', '%d/%m/%Y') def IS_FOURTH(): return SITE_NAME == 'rDrama' and fourth_begin < datetime.datetime.now() < fourth_end +fool_begin = datetime.datetime.strptime(f'1/4/{t.year}', '%d/%m/%Y') +fool_end = datetime.datetime.strptime(f'2/4/{t.year}', '%d/%m/%Y') +def IS_FOOL(): + return True or fool_begin < datetime.datetime.now() < fool_end + CHUD_PHRASES = ( #if you add a phrase, remove one in turn "Trans lives matter", "Black lives matter", diff --git a/files/templates/comments.html b/files/templates/comments.html index 90a376925..0162f5ed4 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -25,7 +25,7 @@ {% if (c.is_banned or c.deleted_utc) and not (v and v.admin_level >= PERMS['POST_COMMENT_MODERATION']) and not (v and v.id == c.author_id) %}
- +