diff --git a/files/assets/css/orgy.css b/files/assets/css/orgy.css new file mode 100644 index 000000000..f2d0bd40b --- /dev/null +++ b/files/assets/css/orgy.css @@ -0,0 +1,14 @@ +.orgy-top-container { + display: flex; + flex-flow: row nowrap; + justify-content: space-around; +} + +.orgy-chat-window-item { + flex-grow: 2; + width: fit-content; +} +.orgy-info-window-item { + max-width: 550px; + width: 550px; +} \ No newline at end of file diff --git a/files/classes/orgy.py b/files/classes/orgy.py new file mode 100644 index 000000000..83fa8d0b5 --- /dev/null +++ b/files/classes/orgy.py @@ -0,0 +1,49 @@ +import time +from math import floor +from random import randint +from urllib.parse import parse_qs, urlencode, urlparse +from flask import g + +from sqlalchemy import Column, ForeignKey +from sqlalchemy.dialects.postgresql import TSVECTOR +from sqlalchemy.orm import relationship, scoped_session +from sqlalchemy.schema import FetchedValue +from sqlalchemy.sql.sqltypes import * + +from files.classes import Base +from files.helpers.config.const import * +from files.helpers.lazy import lazy +from files.helpers.regex import * +from files.helpers.sorting_and_time import * + +class Orgy(Base): + __tablename__ = "orgies" + + youtube_id = Column(String, primary_key=True) + title = Column(String) + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + + def __repr__(self): + return f"<{self.__class__.__name__}(id={self.youtube_id}, title={self.title})>" + + +def get_orgy(): + orgy = g.db.query(Orgy).one_or_none() + return orgy + +def create_orgy(youtube_id, title): + assert not get_orgy() + assert re.match(yt_id_regex, youtube_id) + orgy = Orgy(title=title, youtube_id=youtube_id) + g.db.add(orgy) + g.db.flush() + g.db.commit() + +def end_orgy(): + assert get_orgy() + g.db.query(Orgy).delete() + g.db.flush() + g.db.commit() \ No newline at end of file diff --git a/files/helpers/config/const.py b/files/helpers/config/const.py index 2f0601ef8..9b4b915b7 100644 --- a/files/helpers/config/const.py +++ b/files/helpers/config/const.py @@ -518,6 +518,7 @@ PERMS = { # Minimum admin_level to perform action. 'LOTTERY_VIEW_PARTICIPANTS': 2, 'POST_COMMENT_INFINITE_PINGS': 2, 'IGNORE_1WEEk_EDITING_LIMIT': 2, + 'ORGIES': 2, 'ADMIN_REMOVE': 3, 'ADMIN_ACTIONS_REVERT': 3, diff --git a/files/routes/admin.py b/files/routes/admin.py index 7fb0b11ce..a3537a2b5 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -9,6 +9,7 @@ from psycopg2.errors import UniqueViolation from files.__main__ import app, cache, limiter from files.classes import * +from files.classes.orgy import * from files.helpers.actions import * from files.helpers.alerts import * from files.helpers.cloudflare import * @@ -1906,3 +1907,27 @@ def admin_reset_password(user_id, v): send_repeatable_notification(user.id, text) return {"message": f"@{user.username}'s password has been reset! The new password has been messaged to them!"} + +@app.get("/admin/orgy") +@admin_level_required(PERMS['ORGIES']) +def orgy_control(v): + return render_template("admin/orgy_control.html", v=v, orgy=get_orgy()) + +@app.post("/admin/start_orgy") +@admin_level_required(PERMS['ORGIES']) +def start_orgy(v): + youtube_id = request.values.get("youtube_id") + title = request.values.get("title") + + assert youtube_id + assert title + + create_orgy(youtube_id, title) + + return redirect("/chat") + +@app.post("/admin/stop_orgy") +@admin_level_required(PERMS['ORGIES']) +def stop_orgy(v): + end_orgy() + return redirect("/chat") \ No newline at end of file diff --git a/files/routes/chat.py b/files/routes/chat.py index 35e527337..5ecb6719e 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -13,6 +13,7 @@ from files.helpers.media import * from files.helpers.sanitize import * from files.helpers.alerts import push_notif from files.routes.wrappers import * +from files.classes.orgy import * from files.__main__ import app, cache, limiter @@ -33,6 +34,19 @@ messages = cache.get(f'messages') or {} @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) @is_not_permabanned def chat(v): + if not v.admin_level and TRUESCORE_CHAT_MINIMUM and v.truescore < TRUESCORE_CHAT_MINIMUM: + abort(403, f"Need at least {TRUESCORE_CHAT_MINIMUM} truescore for access to chat!") + orgy = get_orgy() + if orgy: + return render_template("orgy.html", v=v, messages=messages, orgy = orgy) + else: + return render_template("chat.html", v=v, messages=messages) + +@app.get("/old_chat") +@limiter.limit(DEFAULT_RATELIMIT) +@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) +@is_not_permabanned +def old_chat(v): if not v.admin_level and TRUESCORE_CHAT_MINIMUM and v.truescore < TRUESCORE_CHAT_MINIMUM: abort(403, f"Need at least {TRUESCORE_CHAT_MINIMUM} truescore for access to chat!") return render_template("chat.html", v=v, messages=messages) diff --git a/files/templates/admin/admin_home.html b/files/templates/admin/admin_home.html index fb3e6d8a8..05ebeab71 100644 --- a/files/templates/admin/admin_home.html +++ b/files/templates/admin/admin_home.html @@ -98,6 +98,12 @@ {%- endif %} +{% if v.admin_level >= PERMS['ORGIES'] %} +

Misc

+ +{%- endif %}

Statistics