automate more aspects of mn + allow scheduling orgies

master
Aevann 2023-10-13 00:09:38 +03:00
parent 672fee15ef
commit f978df8580
10 changed files with 63 additions and 64 deletions

View File

@ -1,5 +1,6 @@
import time
from flask import g, abort
import requests
from sqlalchemy import Column, or_
from sqlalchemy.sql.sqltypes import *
@ -7,6 +8,7 @@ from sqlalchemy.sql.sqltypes import *
from files.classes import Base
from files.helpers.lazy import lazy
from files.helpers.config.const import *
class Orgy(Base):
__tablename__ = "orgies"
@ -15,7 +17,9 @@ class Orgy(Base):
data = Column(String)
title = Column(String)
created_utc = Column(Integer)
start_utc = Column(Integer)
end_utc = Column(Integer)
started = Column(Boolean, default=False)
def __init__(self, *args, **kwargs):
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
@ -26,8 +30,8 @@ class Orgy(Base):
@property
@lazy
def real_created_utc(self):
t = self.created_utc
def real_start_utc(self):
t = self.start_utc
if int(time.time()) - t > 3000:
t += 303
return t
@ -35,10 +39,17 @@ class Orgy(Base):
def get_orgy(v):
if not (v and v.allowed_in_chat): return None
orgy = g.db.query(Orgy).one_or_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)
if orgy and orgy.end_utc and orgy.end_utc < time.time():
g.db.delete(orgy)
return None
if expired_orgies:
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
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)
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
return orgy

View File

@ -306,7 +306,7 @@ MODACTION_TYPES = {
"icon": 'fa-eye-slash',
"color": 'bg-danger'
},
'start_orgy': {
'schedule_orgy': {
"str": 'started orgy',
"icon": 'fa-tv',
"color": 'bg-success'

View File

@ -88,7 +88,7 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
if every_fri_12:
_create_post(f'Movie Night', f'''Our Movie Night today will show `{get_name()}`.\nThe movies will start at 8 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=8pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4435809/movie-night) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.\nRerun will be Sunday 4 PM EST.''', 11)
_create_post(f'Movie Night', f'''Our Movie Night today will show `{get_names()}`.\nThe movies will start at 8 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=8pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4435809/movie-night) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.\nRerun will be Sunday 4 PM EST.''', 11)
g.db.commit()
if every_fri_23:
@ -96,16 +96,13 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
g.db.commit()
if every_sun_07:
_create_post(f'Movie Night Rerun', f'''Our Movie Night Rerun today will show `{get_name()}`.\nThe movies will start at 4 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=4pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4465675/movie-night-rerun) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.''', 1)
_create_post(f'Movie Night Rerun', f'''Our Movie Night Rerun today will show `{get_names()}`.\nThe movies will start at 4 PM EST. [Here is a timezone converter for whoever needs it.](https://dateful.com/time-zone-converter?t=4pm&tz1=EST-EDT-Eastern-Time). You can also check this [countdown timer](https://www.tickcounter.com/countdown/4465675/movie-night-rerun) instead.\nThey will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.''', 1)
g.db.commit()
if every_sun_19:
_create_post(f'Movie Night Rerun in 60 minutes', 'It will be shown [here](/chat).\nThere will be a 5-minute bathroom break at the 50:00 mark.', 1)
g.db.commit()
if every_sat_00 or every_sun_20:
_create_and_delete_orgy()
if every_sat_03 or every_sun_23:
_delete_all_posts()
g.db.commit()
@ -140,16 +137,13 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_
def cron(**kwargs):
cron_fn(**kwargs)
def get_file():
return max(glob.glob('/orgies/*'), key=os.path.getctime).split('/orgies/')[1]
def get_name():
return get_file().split('.')[0]
def get_names():
return ' and '.join([x[0] for x in g.db.query(Orgy.title).filter_by(type='file').order_by(Orgy.start_utc)])
def _create_post(title, body, pin_hours):
_delete_all_posts()
title += f': {get_name()}'
title += f': {get_names()}'
title_html = filter_emojis_only(title)
body_html = sanitize(body)
@ -184,26 +178,6 @@ def _create_post(title, body, pin_hours):
cache.delete_memoized(frontlist)
def _create_and_delete_orgy():
video_info = ffmpeg.probe(f'/orgies/{get_file()}')
seconds = float(video_info['streams'][0]['duration'])
end_utc = int(time.time() + seconds)
orgy = Orgy(
title=get_name(),
type='file',
data=f'https://videos.watchpeopledie.tv/orgies/{get_file()}',
end_utc = end_utc,
)
g.db.add(orgy)
g.db.commit()
g.db.close()
del g.db
stdout.flush()
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
def _delete_all_posts():
posts = g.db.query(Post).filter_by(author_id=AUTOJANNY_ID, deleted_utc=0).all()
for p in posts:

View File

@ -1942,14 +1942,14 @@ def admin_reset_password(user_id, v):
@app.get("/admin/orgy")
@admin_level_required(PERMS['ORGIES'])
def orgy_control(v):
orgy = g.db.query(Orgy).one_or_none()
return render_template("admin/orgy_control.html", v=v, orgy=orgy)
return render_template("admin/orgy_control.html", v=v, orgy=get_orgy(v))
@app.post("/admin/start_orgy")
@app.post("/admin/schedule_orgy")
@admin_level_required(PERMS['ORGIES'])
def start_orgy(v):
def schedule_orgy(v):
link = request.values.get("link", "").strip()
title = request.values.get("title", "").strip()
start_utc = request.values.get("start_utc", "").strip()
if not link:
abort(400, "A link is required!")
@ -1961,6 +1961,12 @@ def start_orgy(v):
abort(400, "An orgy is already in progress")
normalized_link = normalize_url(link)
if start_utc:
start_utc = int(start_utc)
else:
start_utc = int(time.time())
end_utc = None
if bare_youtube_regex.match(normalized_link):
@ -1982,7 +1988,8 @@ def start_orgy(v):
pass
else:
seconds = float(video_info['streams'][0]['duration'])
end_utc = int(time.time() + seconds)
if seconds > 2.0:
end_utc = int(start_utc + seconds)
else:
abort(400)
@ -1990,20 +1997,18 @@ def start_orgy(v):
title=title,
type=orgy_type,
data=data,
start_utc=start_utc,
end_utc=end_utc,
)
g.db.add(orgy)
ma = ModAction(
kind="start_orgy",
kind="schedule_orgy",
user_id=v.id,
_note=data,
)
g.db.add(ma)
g.db.commit()
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
return redirect('/chat')
@app.post("/admin/stop_orgy")
@ -2021,8 +2026,9 @@ def stop_orgy(v):
)
g.db.add(ma)
g.db.delete(orgy)
orgy.end_utc = int(time.time())
g.db.add(orgy)
requests.post('http://localhost:5001/refresh_chat', headers={"Host": SITE})
get_orgy(v) #don't remove this, it's necessary (trust)
return {"message": "Orgy stopped successfully!"}

View File

@ -71,13 +71,7 @@ def chat(v):
orgy = get_orgy(v)
if orgy:
m = md5()
with open('files/assets/subtitles.vtt', "rb") as f:
data = f.read()
m.update(data)
subtitles_hash = m.hexdigest()
return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, subtitles_hash=subtitles_hash)
return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy)
return render_template("chat.html", v=v, messages=displayed_messages)

View File

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

View File

@ -13,7 +13,7 @@
<div class="body d-lg-flex">
<div class="w-lg-100">
{% if not orgy %}
<form id="orgy" action="/admin/start_orgy" method="post">
<form id="orgy" action="/admin/schedule_orgy" method="post">
<div class="d-lg-flex border-bottom">
<div class="title w-lg-25">
<label for="title">Title</label>
@ -22,17 +22,25 @@
<input id="title" autocomplete="off" type="text" name="title" class="form-control">
</div>
</div>
<div class="d-lg-flex border-bottom">
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="link">Livestream link (youtube, twitch, rumble, mp4 file)</label>
<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>
<div class="d-lg-flex border-bottom mt-3">
<div class="title w-lg-25">
<label for="link">Start time (as an <a rel="nofollow noopener" href="https://epochconverter.com">epoch timestamp</a>)</label>
</div>
<div class="body w-lg-100">
<input autocomplete="off" type="number" step="any" name="start_utc" max="2147483647" class="form-control" placeholder="Leave blank to start orgy now">
</div>
</div>
<input hidden name="formkey" value="{{v|formkey}}">
<div class="d-flex mt-2">
<input id="start-orgy" autocomplete="off" class="btn btn-primary ml-auto" type="submit" value="Start Orgy">
<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>
{% else %}

View File

@ -24,8 +24,11 @@
<iframe src="https://player.twitch.tv/?channel={{orgy.data}}&parent={{SITE}}" frameborder="0" allowfullscreen></iframe>
{% elif orgy.type == 'file' %}
<meta name="referrer" content="strict-origin-when-cross-origin">
<video id="orgy-file" data-created_utc="{{orgy.real_created_utc}}" controls preload="none" src="{{orgy.data}}">
<track label="English" kind="subtitles" srclang="en" src="/assets/subtitles.vtt?x={{subtitles_hash}}" default>
<video id="orgy-file" data-created_utc="{{orgy.real_start_utc}}" controls preload="none" src="{{orgy.data}}">
{% set subtitles_path = '/assets/' ~ orgy.data.split('/')[-1].split('.')[0] ~ '.vtt' %}
{% if os_path.exists(subtitles_path) %}
<track label="English" kind="subtitles" srclang="en" src="{{subtitles_path}}" default>
{% endif %}
</video>
<video id="break-file" class="d-none" controls preload="none" src="/assets/break.mp4" data-run="0"></video>
<script defer src="{{'js/orgy_file.js' | asset}}"></script>

View File

@ -0,0 +1,3 @@
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';