From d16a15d00b41f7b5725207916e87367cb30874a6 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 14 Nov 2024 21:37:40 +0200 Subject: [PATCH] make april fool switches permanent during the event --- files/__main__.py | 2 -- files/classes/user.py | 10 ++++++++-- files/helpers/config/const.py | 3 +++ files/routes/allroutes.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/files/__main__.py b/files/__main__.py index f1907cb80..05f5ac741 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -83,8 +83,6 @@ if "cron" not in argv: cache = Cache(app) Compress(app) -redis_instance = redis.Redis.from_url(app.config["CACHE_REDIS_URL"]) - from files.routes.allroutes import * if "load_chat" in argv: diff --git a/files/classes/user.py b/files/classes/user.py index ad86ae788..6e1e6fc6e 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -1434,12 +1434,18 @@ class User(Base): or (has_request_context() and request.path in {'/notifications/modmail', '/notifications/messages'}): return self + uid = redis_instance.get(f'{self.id}-switched') + if uid: return g.db.get(User, uid) + three_days = time.time() - 259200 - return g.db.query(User).filter( + uid = g.db.query(User.id).filter( User.truescore < self.truescore, User.last_active > three_days, not_(User.username.like('deleted~%')), - ).order_by(User.truescore.desc()).first() or self + ).order_by(User.truescore.desc()).first() + uid = uid[0] if uid else self.id + redis_instance.set(f'{self.id}-switched', uid) + return g.db.get(User, uid) @property @lazy diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index d4de726f6..19b728ea6 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -3,6 +3,7 @@ from os import environ, path import tldextract import datetime +import redis DEFAULT_TIME_FILTER = "all" DEFAULT_THEME = "midnight" @@ -1465,3 +1466,5 @@ else: from flask import abort def stop(code, message=None): abort(code, message) + +redis_instance = redis.Redis.from_url(environ.get("REDIS_URL").strip()) \ No newline at end of file diff --git a/files/routes/allroutes.py b/files/routes/allroutes.py index 031169579..2c491c964 100644 --- a/files/routes/allroutes.py +++ b/files/routes/allroutes.py @@ -5,7 +5,7 @@ from files.helpers.config.const import * from files.helpers.settings import get_setting from files.helpers.cloudflare import CLOUDFLARE_AVAILABLE from files.routes.wrappers import * -from files.__main__ import app, limiter, get_IP, redis_instance +from files.__main__ import app, limiter, get_IP if FEATURES['IP_LOGGING']: from files.classes.ip_logs import *