diff --git a/files/assets/js/admin/orgies.js b/files/assets/js/admin/orgies.js new file mode 100644 index 000000000..b115f4d53 --- /dev/null +++ b/files/assets/js/admin/orgies.js @@ -0,0 +1,8 @@ +function remove_orgy(t, created_utc) { + postToast(t, `/admin/remove_orgy/${created_utc}`, + {}, + () => { + t.parentElement.parentElement.remove() + } + ); +} diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 9b7c17192..aead1eafe 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -127,7 +127,7 @@ if (!location.pathname.endsWith('/submit') && !location.pathname.endsWith('/chat return } - if (location.pathname == '/admin/orgy') { + if (location.pathname == '/admin/orgies') { document.getElementById('start-orgy').click(); return } diff --git a/files/classes/orgy.py b/files/classes/orgy.py index 0126a241a..79020e29d 100644 --- a/files/classes/orgy.py +++ b/files/classes/orgy.py @@ -13,10 +13,10 @@ from files.helpers.config.const import * class Orgy(Base): __tablename__ = "orgies" - type = Column(String, primary_key=True) + created_utc = Column(Integer, primary_key=True) + type = Column(String) data = Column(String) title = Column(String) - created_utc = Column(Integer) start_utc = Column(Integer) end_utc = Column(Integer) started = Column(Boolean, default=False) @@ -36,20 +36,24 @@ class Orgy(Base): t += 303 return t -def get_orgy(v): +def get_running_orgy(v): if not (v and v.allowed_in_chat): return None - expired_orgies = g.db.query(Orgy).filter(Orgy.end_utc != None, Orgy.end_utc < time.time()).all() - for x in expired_orgies: - g.db.delete(x) + refresh = False - if expired_orgies: - requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE}) + expired_orgies = g.db.query(Orgy).filter(Orgy.end_utc != None, Orgy.end_utc < time.time()).all() + for orgy in expired_orgies: + if orgy.started: + refresh = True + g.db.delete(orgy) orgy = g.db.query(Orgy).filter(Orgy.start_utc < time.time()).order_by(Orgy.start_utc).first() if orgy and not orgy.started: orgy.started = True g.db.add(orgy) + refresh = True + + if refresh: requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE}) return orgy diff --git a/files/helpers/config/modaction_types.py b/files/helpers/config/modaction_types.py index 42588c09c..56d454050 100644 --- a/files/helpers/config/modaction_types.py +++ b/files/helpers/config/modaction_types.py @@ -311,7 +311,7 @@ MODACTION_TYPES = { "icon": 'fa-tv', "color": 'bg-success' }, - 'stop_orgy': { + 'remove_orgy': { "str": 'stopped orgy', "icon": 'fa-tv', "color": 'bg-danger' @@ -435,6 +435,7 @@ MODACTION_PRIVILEGED_TYPES = { 'link_accounts', 'delink_accounts', 'enable_login_required', 'reset_password', + 'schedule_orgy', 'remove_orgy', } MODACTION_PRIVILEGED__TYPES = {'progstack_post', 'progstack_comment', 'unprogstack_post', 'unprogstack_comment'} diff --git a/files/routes/admin.py b/files/routes/admin.py index 9a9e4fce3..ebc6abe6b 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1939,10 +1939,11 @@ def admin_reset_password(user_id, v): return {"message": f"@{user.username}'s password has been reset! The new password has been messaged to them!"} -@app.get("/admin/orgy") +@app.get("/admin/orgies") @admin_level_required(PERMS['ORGIES']) def orgy_control(v): - return render_template("admin/orgy_control.html", v=v, orgy=get_orgy(v)) + orgies = g.db.query(Orgy).order_by(Orgy.start_utc).all() + return render_template("admin/orgy_control.html", v=v, orgies=orgies) @app.post("/admin/schedule_orgy") @admin_level_required(PERMS['ORGIES']) @@ -1958,14 +1959,11 @@ def schedule_orgy(v): if not title: abort(400, "A title is required!") - if get_orgy(v): - abort(400, "An orgy is already in progress") - normalized_link = normalize_url(link) if start_utc: start_utc = int(start_utc) - redir = '/admin/orgy' + redir = '/admin/orgies' else: start_utc = int(time.time()) redir = '/chat' @@ -2009,23 +2007,22 @@ def schedule_orgy(v): return redirect(redir) -@app.post("/admin/stop_orgy") +@app.post("/admin/remove_orgy/") @admin_level_required(PERMS['ORGIES']) -def stop_orgy(v): - orgy = g.db.query(Orgy).one_or_none() - - if not orgy: - abort(400, "There is no orgy in progress right now!") +def remove_orgy(v, created_utc): + orgy = g.db.query(Orgy).filter_by(created_utc=created_utc).one() ma = ModAction( - kind="stop_orgy", + kind="remove_orgy", user_id=v.id, _note=orgy.data, ) g.db.add(ma) + started = orgy.started g.db.delete(orgy) g.db.commit() - requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE}) + if started: + requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE}) return {"message": "Orgy stopped successfully!"} diff --git a/files/routes/chat.py b/files/routes/chat.py index 7b2b05eaf..f8a9fe2cc 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -69,7 +69,7 @@ def chat(v): displayed_messages = {k: val for k, val in messages.items() if val["user_id"] not in v.userblocks} - orgy = get_orgy(v) + orgy = get_running_orgy(v) if orgy: x = secrets.token_urlsafe(8) return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, x=x) diff --git a/files/routes/jinja2.py b/files/routes/jinja2.py index 340bd34b1..9397ba054 100644 --- a/files/routes/jinja2.py +++ b/files/routes/jinja2.py @@ -9,7 +9,7 @@ from PIL import ImageColor from sqlalchemy import text from files.classes.user import User -from files.classes.orgy import get_orgy +from files.classes.orgy import get_running_orgy from files.helpers.assetcache import assetcache_path from files.helpers.config.const import * from files.helpers.const_stateful import OVER_18_EMOJIS @@ -150,5 +150,5 @@ def inject_constants(): "CHUD_PHRASES":CHUD_PHRASES, "hasattr":hasattr, "calc_users":calc_users, "HOLE_INACTIVITY_DELETION":HOLE_INACTIVITY_DELETION, "LIGHT_THEMES":LIGHT_THEMES, "OVER_18_EMOJIS":OVER_18_EMOJIS, "MAX_IMAGE_AUDIO_SIZE_MB":MAX_IMAGE_AUDIO_SIZE_MB, "MAX_IMAGE_AUDIO_SIZE_MB_PATRON":MAX_IMAGE_AUDIO_SIZE_MB_PATRON, "MAX_VIDEO_SIZE_MB":MAX_VIDEO_SIZE_MB, "MAX_VIDEO_SIZE_MB_PATRON":MAX_VIDEO_SIZE_MB_PATRON, - "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_orgy":get_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, + "CURSORMARSEY_DEFAULT":CURSORMARSEY_DEFAULT, "SNAPPY_ID":SNAPPY_ID, "get_running_orgy":get_running_orgy, "TRUESCORE_MINIMUM":TRUESCORE_MINIMUM, "bar_position":bar_position, } diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index c7639b9ef..9662aab68 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -7,7 +7,7 @@ {% if v.admin_level >= PERMS['ORGIES'] %}

Orgies

{%- endif %} diff --git a/files/templates/admin/orgy_control.html b/files/templates/admin/orgy_control.html index 36d280665..136f843a9 100644 --- a/files/templates/admin/orgy_control.html +++ b/files/templates/admin/orgy_control.html @@ -12,56 +12,81 @@
- {% if not orgy %} -
-
-
- -
-
- -
+ +
+
+
-
-
- -
-
- -
+
+
-
-
- -
-
- -
+
+
+
+
-
-
- -
-
- -
+
+
- -
- +
+
+
+
- - {% else %} -
- -
- +
+
- - {% endif %} +
+
+
+ +
+
+ +
+
+ +
+ +
+
+ +
+ + + + + + + + + + + + + {% for orgy in orgies %} + + + + + {% if orgy.started %} + + {% else %} + + {% endif %} + + + + {% endfor %} +
TypeTitleLinkStarts onEnds on
{{orgy.type}}{{orgy.title}}{{orgy.data}}Started + +
+
+ + {% endblock %} diff --git a/files/templates/default.html b/files/templates/default.html index 52c847035..e8eed8ccc 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -22,7 +22,7 @@ {% set src = hole.random_banner() %} {% set alt = ['/h/', hole, 'banner']|join %} {% set class = 'site-banner-hole' %} - {% elif get_orgy(v) and os_path.exists(path ~ "/orgy_banners") %} + {% elif get_running_orgy(v) and os_path.exists(path ~ "/orgy_banners") %} {% set src = macros.random_image("assets/images/" ~ SITE_NAME ~ "/orgy_banners") %} {% set href = "/chat" %} {% set expand = false %} diff --git a/files/templates/header.html b/files/templates/header.html index b5a27b265..d16e0d8fc 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -247,13 +247,13 @@ {%- if FEATURES['CHAT'] -%}