make april fool switches permanent during the event

master
Aevann 2024-11-14 21:37:40 +02:00
parent bee874a3d1
commit d16a15d00b
4 changed files with 12 additions and 5 deletions

View File

@ -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:

View File

@ -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

View File

@ -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())

View File

@ -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 *