From 76866e2b077c27f5bacd487b222e69fb55b7b06d Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 1 Feb 2024 01:28:39 +0200 Subject: [PATCH] allow under siege customization --- files/assets/css/main.css | 12 +++++++++ files/helpers/actions.py | 17 +++++------- files/helpers/config/const.py | 12 ++++++++- files/helpers/config/modaction_types.py | 16 +++++------- files/helpers/settings.py | 1 - files/routes/comments.py | 2 +- files/templates/admin/admin_home.html | 3 +++ files/templates/admin/under_siege.html | 26 +++++++++++++++++++ .../20240201-under-siege-customization.sql | 3 +++ 9 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 files/templates/admin/under_siege.html create mode 100644 migrations/20240201-under-siege-customization.sql diff --git a/files/assets/css/main.css b/files/assets/css/main.css index f840e724c..3a6e8d828 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -2331,6 +2331,12 @@ a.bg-light:hover, a.bg-light:focus, button.bg-light:hover, button.bg-light:focus z-index: 1020; } } +.w-50 { + width: 50% !important; +} +.w-75 { + width: 75% !important; +} .w-100 { width: 100% !important; } @@ -4712,6 +4718,12 @@ ul.comment-section { .rounded-md { border-radius: 0.35rem; } + .w-md-25 { + width: 25% !important; + } + .w-md-100 { + width: 100% !important; + } } @media (min-width: 992px) { .rounded-lg { diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 05e369b38..3bd37bcad 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -516,21 +516,16 @@ def execute_antispam_comment_check(body, v): def execute_under_siege(v, target, body, kind): if v.shadowbanned: return - if not get_setting("under_siege"): return if v.admin_level >= PERMS['BYPASS_UNDER_SIEGE_MODE']: return - if SITE == 'watchpeopledie.tv' and kind == 'normal_comment': + thresholds = cache.get("under_siege_thresholds") + if not thresholds: + thresholds = DEFAULT_UNDER_SIEGE_THRESHOLDS + cache.set("under_siege_thresholds", thresholds) + + if v.age > thresholds[kind] * 60: return - if kind in {'message', 'report'} and SITE == 'rdrama.net': - threshold = 86400 - elif kind != 'message' and SITE == 'watchpeopledie.tv': - threshold = 86400 - else: - threshold = UNDER_SIEGE_AGE_THRESHOLD - - if v.age > threshold: return - unshadowbannedcels = [x[0] for x in g.db.query(ModAction.target_user_id).filter_by(kind='unshadowban')] if v.id in unshadowbannedcels: return diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 4f7a197a7..5888d8eda 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -203,6 +203,7 @@ PERMS = { # Minimum admin_level to perform action. 'MODERATE_PENDING_SUBMITTED_ASSETS': 3, 'UPDATE_ASSETS': 3, 'DELETE_MEDIA': 3, + 'CHANGE_UNDER_SIEGE': 3, 'PROGSTACK': 4, 'UNDO_AWARD_PINS': 4, @@ -533,7 +534,16 @@ PFP_DEFAULT_MARSEY = True NEW_USER_AGE = 7 * 86400 NOTIFICATION_SPAM_AGE_THRESHOLD = 0 COMMENT_SPAM_LENGTH_THRESHOLD = 0 -UNDER_SIEGE_AGE_THRESHOLD = 10 * 60 + +DEFAULT_UNDER_SIEGE_THRESHOLDS = { + "chat": 0, + "normal comment": 0, + "wall comment": 0, + "post": 0, + "report": 0, + "modmail": 0, + "message": 0, +} HOLE_REQUIRED = False HOLE_COST = 0 diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index e91874ad3..1fe379bdf 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -46,6 +46,11 @@ MODACTION_TYPES = { "icon": 'fa-lock', "color": 'bg-danger' }, + 'change_under_siege': { + "str": 'changed under siege thresholds', + "icon": 'fa-shield', + "color": 'bg-muted' + }, 'delete_media': { "str": 'deleted media', "icon": 'fa-trash-alt', @@ -91,11 +96,6 @@ MODACTION_TYPES = { "icon": 'fa-shield', "color": 'bg-muted' }, - 'disable_under_siege': { - "str": 'disabled under siege mode', - "icon": 'fa-shield', - "color": 'bg-muted' - }, 'disable_dm_media': { "str": 'disabled DM media', "icon": 'fa-images', @@ -166,11 +166,6 @@ MODACTION_TYPES = { "icon": 'fa-shield', "color": 'bg-success' }, - 'enable_under_siege': { - "str": 'enabled under siege mode', - "icon": 'fa-shield', - "color": 'bg-success', - }, 'enable_dm_media': { "str": 'enabled DM media', "icon": 'fa-images', @@ -442,6 +437,7 @@ MODACTION_PRIVILEGED_TYPES = { 'reset_password', 'schedule_orgy', 'remove_orgy', 'insert_transaction', + 'change_under_siege_thresholds', } MODACTION_PRIVILEGED__TYPES = {'progstack_post', 'progstack_comment', 'unprogstack_post', 'unprogstack_comment'} diff --git a/files/helpers/settings.py b/files/helpers/settings.py index 4cba057b8..8012e80d1 100644 --- a/files/helpers/settings.py +++ b/files/helpers/settings.py @@ -14,7 +14,6 @@ _SETTINGS = { "fart_mode": False, "read_only_mode": False, "offline_mode": False, - "under_siege": False, "dm_media": True, } diff --git a/files/routes/comments.py b/files/routes/comments.py index 1747e8ce4..d3c224d62 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -306,7 +306,7 @@ def comment(v): execute_blackjack(v, c, c.body, "comment") - kind = "normal_comment" if posting_to_post else "wall_comment" + kind = "normal comment" if posting_to_post else "wall comment" execute_under_siege(v, c, c.body, kind) if c.level == 1: c.top_comment_id = c.id diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index 721a8d6e0..7135175c1 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -98,6 +98,9 @@ {% if v.admin_level >= PERMS['VIEW_ALT_VOTES'] %}
  • Alt Vote Analysis
  • {% endif %} + {% if v.admin_level >= PERMS['CHANGE_UNDER_SIEGE'] %} +
  • Change Under Siege Thresholds
  • + {% endif %} {% if FEATURES['BADGES'] and v.admin_level >= PERMS['USER_BADGES'] -%} diff --git a/files/templates/admin/under_siege.html b/files/templates/admin/under_siege.html new file mode 100644 index 000000000..da5c610da --- /dev/null +++ b/files/templates/admin/under_siege.html @@ -0,0 +1,26 @@ +{% extends "settings2.html" %} +{% block pagetitle %}Under Siege Thresholds{% endblock %} + {% block content %} +
    +
    Thresholds in Minutes
    +
    +
    +
    + {% for name, value in thresholds.items() %} +
    + + +
    + {% endfor %} +
    + +
    +
    +
    +{% endblock %} diff --git a/migrations/20240201-under-siege-customization.sql b/migrations/20240201-under-siege-customization.sql new file mode 100644 index 000000000..981c747dc --- /dev/null +++ b/migrations/20240201-under-siege-customization.sql @@ -0,0 +1,3 @@ +delete from modactions where kind='enable_under_siege' or kind='disable_under_siege'; + +delete settings in file