From 17852d30e6dd36c5e40c754abfa85678abe3899b Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 12 Apr 2022 19:29:52 +0200 Subject: [PATCH] fart mode --- .gitignore | 3 ++- files/__main__.py | 2 +- files/classes/mod_logs.py | 10 +++++++++ files/routes/admin.py | 29 ++++++++++++++++++++++++- files/routes/posts.py | 6 ++++- files/templates/admin/admin_home.html | 5 +++++ files/templates/authforms.html | 4 ++-- files/templates/chat.html | 2 +- files/templates/default.html | 4 ++-- files/templates/log.html | 4 ++-- files/templates/login.html | 2 +- files/templates/login_2fa.html | 2 +- files/templates/settings.html | 2 +- files/templates/settings2.html | 4 ++-- files/templates/sign_up.html | 2 +- files/templates/sign_up_failed_ref.html | 2 +- files/templates/submission.html | 2 +- files/templates/submit.html | 4 ++-- 18 files changed, 68 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 8912b0ea1..209ca9214 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ venv/ .sass-cache/ flask_session/ .DS_Store -disable_signups \ No newline at end of file +disable_signups +fart_mode \ No newline at end of file diff --git a/files/__main__.py b/files/__main__.py index 0b2d69278..6c4a81441 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -17,7 +17,7 @@ from sys import stdout, argv import faulthandler from json import loads -for f in (f'files/templates/sidebar_{environ.get("SITE_NAME").strip()}.html', 'disable_signups'): +for f in (f'files/templates/sidebar_{environ.get("SITE_NAME").strip()}.html', 'disable_signups', 'fart_mode'): if not path.exists(f): with open(f, 'w', encoding="utf-8"): pass diff --git a/files/classes/mod_logs.py b/files/classes/mod_logs.py index 720aad08c..e16e6cea6 100644 --- a/files/classes/mod_logs.py +++ b/files/classes/mod_logs.py @@ -175,6 +175,11 @@ ACTIONTYPES = { "icon": 'fa-flag', "color": 'bg-danger' }, + 'disable_fart_mode': { + "str": 'disabled fart mode', + "icon": 'fa-gas-pump-slash', + "color": 'bg-danger' + }, 'disable_signups': { "str": 'disabled signups', "icon": 'fa-users', @@ -210,6 +215,11 @@ ACTIONTYPES = { "icon": 'fa-edit', "color": 'bg-primary' }, + 'enable_fart_mode': { + "str": 'enabled fart mode', + "icon": 'fa-gas-pump', + "color": 'bg-success' + }, 'enable_signups': { "str": 'enabled signups', "icon": 'fa-users', diff --git a/files/routes/admin.py b/files/routes/admin.py index 5b17200b0..94eaec643 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -528,7 +528,9 @@ def admin_home(v): x2 = response == 'under_attack' - return render_template("admin/admin_home.html", v=v, x=x, x2=x2) + with open('fart_mode', 'r') as f: x3 = f.read() + + return render_template("admin/admin_home.html", v=v, x=x, x2=x2, x3=x3) @app.post("/admin/disable_signups") @admin_level_required(3) @@ -555,6 +557,31 @@ def disable_signups(v): g.db.commit() return {"message": "Signups disabled!"} +@app.post("/admin/fart_mode") +@admin_level_required(3) +def fart_mode(v): + with open('fart_mode', 'r') as f: content = f.read() + + with open('fart_mode', 'w') as f: + if content == "yes": + f.write("no") + ma = ModAction( + kind="enable_fart_mode", + user_id=v.id, + ) + g.db.add(ma) + g.db.commit() + return {"message": "Fart mode enabled!"} + else: + f.write("yes") + ma = ModAction( + kind="disable_fart_mode", + user_id=v.id, + ) + g.db.add(ma) + g.db.commit() + return {"message": "Fart mode disabled!"} + @app.post("/admin/purge_cache") @admin_level_required(3) diff --git a/files/routes/posts.py b/files/routes/posts.py index 14432034f..1f0a20b7d 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -253,9 +253,13 @@ def post_id(pid, anything=None, v=None, sub=None): g.db.commit() if request.headers.get("Authorization"): return post.json else: + with open('fart_mode', 'r') as f: + if f.read() == "yes": fart = True + else: fart = False + if post.is_banned and not (v and (v.admin_level > 1 or post.author_id == v.id)): template = "submission_banned.html" else: template = "submission.html" - return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset, sub=post.subr) + return render_template(template, v=v, p=post, ids=list(ids), sort=sort, render_replies=True, offset=offset, sub=post.subr, fart=fart) @app.get("/viewmore///") @limiter.limit("1/second;30/minute;200/hour;1000/day") diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index dc31487c4..98c300e5f 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -68,6 +68,11 @@ +
+ + +
+ {% endif %} diff --git a/files/templates/authforms.html b/files/templates/authforms.html index 83e570209..992805d82 100644 --- a/files/templates/authforms.html +++ b/files/templates/authforms.html @@ -15,7 +15,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/chat.html b/files/templates/chat.html index 7290fb3ff..654a65258 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -14,7 +14,7 @@ Chat - + {% if v.css %} diff --git a/files/templates/default.html b/files/templates/default.html index 5b979d6fa..52ee8b41a 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -7,7 +7,7 @@ {% if v %} - + {% if v.agendaposter %} - + {% endif %} diff --git a/files/templates/log.html b/files/templates/log.html index 36ba50875..826f0e6cc 100644 --- a/files/templates/log.html +++ b/files/templates/log.html @@ -6,7 +6,7 @@ {% block content %} {% if v %} - + {% if v.agendaposter %} - + {% endif %}
diff --git a/files/templates/login.html b/files/templates/login.html index 6cff61733..df4f3ba18 100644 --- a/files/templates/login.html +++ b/files/templates/login.html @@ -18,7 +18,7 @@ {% endblock %} - + diff --git a/files/templates/login_2fa.html b/files/templates/login_2fa.html index 73394680a..2976c93f7 100644 --- a/files/templates/login_2fa.html +++ b/files/templates/login_2fa.html @@ -14,7 +14,7 @@ 2-Step Login - {{SITE_NAME}} - + diff --git a/files/templates/settings.html b/files/templates/settings.html index 5fdcfc983..f7b5a1ef7 100644 --- a/files/templates/settings.html +++ b/files/templates/settings.html @@ -34,7 +34,7 @@ - + {% if v.agendaposter %} - + {% else %} - + {% endif %} diff --git a/files/templates/sign_up.html b/files/templates/sign_up.html index 5ec071422..b333203ef 100644 --- a/files/templates/sign_up.html +++ b/files/templates/sign_up.html @@ -31,7 +31,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}Sign up - {{SITE_NAME}}{% endif %} - + diff --git a/files/templates/sign_up_failed_ref.html b/files/templates/sign_up_failed_ref.html index 2ecceb7f2..1517c8fd0 100644 --- a/files/templates/sign_up_failed_ref.html +++ b/files/templates/sign_up_failed_ref.html @@ -32,7 +32,7 @@ {% if ref_user %}{{ref_user.username}} invites you to {{SITE_NAME}}{% else %}{{SITE_NAME}}{% endif %} - + diff --git a/files/templates/submission.html b/files/templates/submission.html index c80f730dd..8080c329c 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -36,7 +36,7 @@ {% endif %} -{% if SITE_NAME == 'rDrama' and not (v and v.has_badge(128)) %} +{% if fart and not (v and v.has_badge(128)) %}