add more orgy controls

pull/216/head
Aevann 2023-10-13 18:56:12 +03:00
parent 13e3760890
commit f61ba62426
13 changed files with 113 additions and 75 deletions

View File

@ -0,0 +1,8 @@
function remove_orgy(t, created_utc) {
postToast(t, `/admin/remove_orgy/${created_utc}`,
{},
() => {
t.parentElement.parentElement.remove()
}
);
}

View File

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

View File

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

View File

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

View File

@ -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/<int:created_utc>")
@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!"}

View File

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

View File

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

View File

@ -7,7 +7,7 @@
{% if v.admin_level >= PERMS['ORGIES'] %}
<h4>Orgies</h4>
<ul>
<li><a href="/admin/orgy">Schedule/Stop Orgy</a></li>
<li><a href="/admin/orgies">Schedule/Stop Orgy</a></li>
</ul>
{%- endif %}

View File

@ -12,56 +12,81 @@
</div>
<div class="body d-lg-flex">
<div class="w-lg-100">
{% if not orgy %}
<form id="orgy" action="/admin/schedule_orgy" method="post">
<div class="d-lg-flex border-bottom mt-5">
<div class="title w-lg-25">
<label for="title">Title</label>
</div>
<div class="body w-lg-100">
<input id="title" autocomplete="off" type="text" name="title" class="form-control">
</div>
<form id="orgy" action="/admin/schedule_orgy" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRReload(this)">
<div class="d-lg-flex border-bottom mt-5">
<div class="title w-lg-25">
<label for="title">Title</label>
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="link">Link (youtube, twitch, rumble, mp4 file)</label>
</div>
<div class="body w-lg-100">
<input id="link" autocomplete="off" type="text" name="link" class="form-control">
</div>
<div class="body w-lg-100">
<input id="title" autocomplete="off" type="text" name="title" class="form-control">
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="start_utc">Start time (as an <a rel="nofollow noopener" href="https://epochconverter.com">epoch timestamp</a>)</label>
</div>
<div class="body w-lg-100">
<input id="start_utc" autocomplete="off" type="number" step="any" name="start_utc" max="2147483647" class="form-control" placeholder="Leave blank to start orgy now">
</div>
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="link">Link (youtube, twitch, rumble, mp4 file)</label>
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="duration">Duration (in seconds)</label>
</div>
<div class="body w-lg-100">
<input id="duration" autocomplete="off" type="number" step="any" name="duration" max="2147483647" class="form-control" placeholder="Optional">
</div>
<div class="body w-lg-100">
<input id="link" autocomplete="off" type="text" name="link" class="form-control">
</div>
<input hidden name="formkey" value="{{v|formkey}}">
<div class="d-flex mt-3">
<input id="start-orgy" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Schedule Orgy">
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="start_utc">Start time (as an <a rel="nofollow noopener" href="https://epochconverter.com">epoch timestamp</a>)</label>
</div>
</form>
{% else %}
<form id="orgy" action="/admin/stop_orgy" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRReload(this)">
<input hidden name="formkey" value="{{v|formkey}}">
<div class="d-flex mt-2">
<input autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Stop Orgy">
<div class="body w-lg-100">
<input id="start_utc" autocomplete="off" type="number" step="any" name="start_utc" max="2147483647" class="form-control" placeholder="Leave blank to start orgy now">
</div>
</form>
{% endif %}
</div>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="duration">Duration (in seconds)</label>
</div>
<div class="body w-lg-100">
<input id="duration" autocomplete="off" type="number" step="any" name="duration" max="2147483647" class="form-control" placeholder="Optional">
</div>
</div>
<input hidden name="formkey" value="{{v|formkey}}">
<div class="d-flex mt-3">
<input id="start-orgy" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Schedule Orgy">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="overflow-x-auto mt-3">
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>Type</th>
<th>Title</th>
<th>Link</th>
<th>Starts on</th>
<th>Ends on</th>
<th class="disable-sort-click"></th>
</tr>
</thead>
{% for orgy in orgies %}
<tr>
<td>{{orgy.type}}</td>
<td>{{orgy.title}}</td>
<td>{{orgy.data}}</td>
{% if orgy.started %}
<td>Started</td>
{% else %}
<td data-time="{{orgy.start_utc}}"></td>
{% endif %}
<td {% if orgy.end_utc %}data-time="{{orgy.end_utc}}"{% endif %}></td>
<td>
<button type="button" class="btn btn-danger btn-block" data-nonce="{{g.nonce}}" data-areyousure="remove_orgy(this, {{orgy.created_utc}})" data-onclick="areyousure(this)">Remove</button>
</td>
</tr>
{% endfor %}
</table>
</div>
<script defer src="{{'js/admin/orgies.js' | asset}}"></script>
{% endblock %}

View File

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

View File

@ -247,13 +247,13 @@
{%- if FEATURES['CHAT'] -%}
<li class="nav-item d-none d-lg-flex align-items-center justify-content-center text-center mx-1" id="header--chat--item">
<a class="nav-link position-relative" href="/chat" style="margin-top: {% if get_orgy(v) %}-4px{% else %}-1.6px{% endif %} !important">
{% if get_orgy(v) %}
<a class="nav-link position-relative" href="/chat" style="margin-top: {% if get_running_orgy(v) %}-4px{% else %}-1.6px{% endif %} !important">
{% if get_running_orgy(v) %}
<img src="{{SITE_FULL_IMAGES}}/i/orgy.webp" width="30">
{% else %}
<i class="fas fa-messages" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Chat"></i>
{% endif %}
<b id="chat-count-header-bar" class="text-lg {% if get_orgy(v) or g.loggedin_chat > 40 %}text-danger{% elif g.loggedin_chat > 20 %}text-yellow{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Users in chat right now">
<b id="chat-count-header-bar" class="text-lg {% if get_running_orgy(v) or g.loggedin_chat > 40 %}text-danger{% elif g.loggedin_chat > 20 %}text-yellow{% endif %}" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Users in chat right now">
{{g.loggedin_chat}}
</b>
</a>

View File

@ -47,10 +47,10 @@
</button>
{% if v %}
{%- if FEATURES['CHAT'] -%}
<button type="button" class="nobackground border-0 col px-0 btn btn-dead m-0 {% if not get_orgy(v) %}pt-0{% endif %}">
<button type="button" class="nobackground border-0 col px-0 btn btn-dead m-0 {% if not get_running_orgy(v) %}pt-0{% endif %}">
<a href="/chat" class="text-decoration-none">
<div class="text-center {% if request|selected_tab=='chat' %}text-primary{% else %}text-muted{% endif %}">
{%- if get_orgy(v) -%}
{%- if get_running_orgy(v) -%}
<img src="{{SITE_FULL_IMAGES}}/i/orgy.webp" width="30">
<div class="text-small-extra text-danger">Chat ({{g.loggedin_chat}})</div>
{%- else -%}

View File

@ -1,3 +1,6 @@
alter table orgies add column start_utc int not null;
alter table orgies add column started bool not null;
update modactions set kind='schedule_orgy' where kind='start_orgy';
update modactions set kind='remove_orgy' where kind='stop_orgy';
ALTER TABLE orgies DROP CONSTRAINT orgies_pkey;
ALTER TABLE orgies ADD PRIMARY KEY (created_utc);