From d089d18e2d69d3118931639bca9d47849b82df94 Mon Sep 17 00:00:00 2001 From: Aevann Date: Mon, 25 Sep 2023 01:12:42 +0300 Subject: [PATCH] merge /chat and /orgy again --- files/assets/js/chat.js | 32 ++++++++--------- files/assets/js/core.js | 2 +- files/assets/js/emoji_modal.js | 2 +- files/classes/orgy.py | 3 +- files/helpers/cron.py | 10 +++--- files/routes/admin.py | 6 ++-- files/routes/chat.py | 41 ++++++---------------- files/routes/static.py | 8 +++++ files/routes/wrappers.py | 2 -- files/templates/header.html | 30 ++++++---------- files/templates/mobile_navigation_bar.html | 33 ++++++++--------- files/templates/orgy.html | 2 +- nginx.conf | 5 +-- 13 files changed, 71 insertions(+), 105 deletions(-) diff --git a/files/assets/js/chat.js b/files/assets/js/chat.js index c65a144de..da44df86f 100644 --- a/files/assets/js/chat.js +++ b/files/assets/js/chat.js @@ -28,12 +28,10 @@ let focused = true; let is_typing = false; let alert=true; -const page_title = document.getElementsByTagName('title')[0].innerHTML; - function flash(){ let title = document.getElementsByTagName('title')[0] if (notifs >= 1 && !focused){ - title.innerHTML = `[+${notifs}] ${page_title}`; + title.innerHTML = `[+${notifs}] Chat`; if (alert) { icon.href = `/i/${site_name}/alert.ico?v=3009` alert=false; @@ -47,7 +45,7 @@ function flash(){ else { icon.href = `/i/${site_name}/icon.webp?x=6` notifs = 0 - title.innerHTML = page_title; + title.innerHTML = 'Chat'; } if (is_typing) { @@ -368,21 +366,19 @@ document.addEventListener('DOMContentLoaded', function () { box.scrollTo(0, box.scrollHeight) }); -if (location.pathname == '/orgy') { - const now = new Date(); - const day_of_week = now.getUTCDay() +const now = new Date(); +const day_of_week = now.getUTCDay() - if ([4,5,7].includes(day_of_week)) { - let hour - if (day_of_week == 7) hour = 20 - else hour = 0 +if ([4,5,7].includes(day_of_week)) { + let hour + if (day_of_week == 7) hour = 20 + else hour = 0 - let millis = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), hour, 0, 10) - now; - if (millis < 0) - millis += 86400000; + let millis = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), hour, 0, 10) - now; + if (millis < 0) + millis += 86400000; - const minutes = Math.round(millis/1000/60*10)/10 - console.log(`Refreshing page in ${minutes} minutes`) - setTimeout(() => location.reload(), millis); - } + const minutes = Math.round(millis/1000/60*10)/10 + console.log(`Refreshing page in ${minutes} minutes`) + setTimeout(() => location.reload(), millis); } diff --git a/files/assets/js/core.js b/files/assets/js/core.js index 4d7a47fac..608f9065c 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -388,7 +388,7 @@ if (is_pwa) { } const gbrowser = document.getElementById('gbrowser').value -if (location.pathname != '/orgy' && (gbrowser == 'iphone' || gbrowser == 'mac')) { +if (location.pathname != '/chat' && (gbrowser == 'iphone' || gbrowser == 'mac')) { const videos = document.querySelectorAll('video') for (const video of videos) { diff --git a/files/assets/js/emoji_modal.js b/files/assets/js/emoji_modal.js index b402f4a6e..e431c49d6 100644 --- a/files/assets/js/emoji_modal.js +++ b/files/assets/js/emoji_modal.js @@ -423,7 +423,7 @@ function populate_speed_emoji_modal(results, textbox) close_inline_speed_emoji_modal() textbox.value = textbox.value.replace(new RegExp(current_word+"(?=\\s|$)", "gi"), `:${name}: `) textbox.focus() - if (!['/chat','/orgy'].includes(location.pathname)) { + if (location.pathname != '/chat') { markdown(textbox) } }); diff --git a/files/classes/orgy.py b/files/classes/orgy.py index 65c523f2e..efcfc238a 100644 --- a/files/classes/orgy.py +++ b/files/classes/orgy.py @@ -31,5 +31,6 @@ class Orgy(Base): t += 303 return t -def get_orgy(): +def get_orgy(v): + if not (v and v.allowed_in_chat): return None return g.db.query(Orgy).one_or_none() diff --git a/files/helpers/cron.py b/files/helpers/cron.py index b1ae5a277..d74b8ee31 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -79,19 +79,19 @@ def cron_fn(every_5m, every_1d, every_fri_12, every_fri_23, every_sat_00, every_ g.db.commit() if every_fri_12: - _create_post(f'Movie Night', f'''Our Movie Night today will show `{get_name()}`.\nThe movie 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.\nIt will be shown [here](/orgy).\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_name()}`.\nThe movie 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.\nIt 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: - _create_post(f'Movie Night in 60 minutes', 'It will be shown [here](/orgy).\nThere will be a 5-minute bathroom break at the 50:00 mark.\nRerun will be Sunday 4 PM EST.', 1) + _create_post(f'Movie Night in 60 minutes', 'It 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.', 1) g.db.commit() if every_sun_07: - _create_post(f'Movie Night Rerun', f'''Our Movie Night Rerun today will show `{get_name()}`.\nThe movie 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.\nIt will be shown [here](/orgy).\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_name()}`.\nThe movie 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.\nIt 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](/orgy).\nThere will be a 5-minute bathroom break at the 50:00 mark.', 1) + _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: @@ -154,7 +154,7 @@ def _create_post(title, body, pin_hours): new=False, app_id=None, is_bot=False, - url='/orgy', + url='/chat', body=body, body_html=body_html, embed=None, diff --git a/files/routes/admin.py b/files/routes/admin.py index abeed62c9..977d78474 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -1937,7 +1937,7 @@ def admin_reset_password(user_id, v): @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()) + return render_template("admin/orgy_control.html", v=v, orgy=get_orgy(v)) @app.post("/admin/start_orgy") @admin_level_required(PERMS['ORGIES']) @@ -1951,7 +1951,7 @@ def start_orgy(v): if not title: abort(400, "A title is required!") - if get_orgy(): + if get_orgy(v): abort(400, "An orgy is already in progress") normalized_link = normalize_url(link) @@ -1978,7 +1978,7 @@ def start_orgy(v): ) g.db.add(orgy) - return redirect('/orgy') + return redirect('/chat') @app.post("/admin/stop_orgy") @admin_level_required(PERMS['ORGIES']) diff --git a/files/routes/chat.py b/files/routes/chat.py index b2be9b3d6..c957b87f3 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -28,23 +28,19 @@ socketio = SocketIO( sessions = [] muted = cache.get(f'muted') or {} -ALLOWED_REFERRERS = {f'{SITE_FULL}/chat', f'{SITE_FULL}/orgy'} +ALLOWED_REFERRERS = {f'{SITE_FULL}/chat'} messages = cache.get(f'messages') or { f'{SITE_FULL}/chat': {}, - f'{SITE_FULL}/orgy': {}, } typing = { f'{SITE_FULL}/chat': [], - f'{SITE_FULL}/orgy': [], } online = { f'{SITE_FULL}/chat': [], - f'{SITE_FULL}/orgy': [], } cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0) -cache.set('loggedin_orgy', len(online[f'{SITE_FULL}/orgy']), timeout=0) def auth_required_socketio(f): def wrapper(*args, **kwargs): @@ -76,31 +72,18 @@ def chat(v): displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/chat"].items() if val["user_id"] not in v.userblocks} + 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("chat.html", v=v, messages=displayed_messages) -@app.get("/orgy") -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) -@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) -@auth_required -def orgy(v): - if not v.allowed_in_chat: - abort(403, CHAT_ERROR_MESSAGE) - - orgy = get_orgy() - - displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/orgy"].items() if val["user_id"] not in v.userblocks} - - if not orgy: - return render_template("chat.html", v=v, messages=displayed_messages) - - 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) - @socketio.on('speak') @is_not_banned_socketio def speak(data, v): @@ -197,9 +180,7 @@ def speak(data, v): def refresh_online(): emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True) - cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0) - cache.set('loggedin_orgy', len(online[f'{SITE_FULL}/orgy']), timeout=0) @socketio.on('connect') @auth_required_socketio diff --git a/files/routes/static.py b/files/routes/static.py index c07a5006f..98fa1e3f6 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -420,3 +420,11 @@ def donate(v): if v and (v.shadowbanned or v.chud == 1 or v.is_permabanned): abort(404) return render_template(f'donate.html', v=v) + + +@app.get("/orgy") +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400) +@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID) +@auth_required +def orgy(v): + return redirect("/chat") diff --git a/files/routes/wrappers.py b/files/routes/wrappers.py index ca9ec99a0..b6b154ca9 100644 --- a/files/routes/wrappers.py +++ b/files/routes/wrappers.py @@ -31,13 +31,11 @@ def calc_users(): g.loggedin_counter = 0 g.loggedout_counter = 0 g.loggedin_chat = 0 - g.loggedin_orgy = 0 v = getattr(g, 'v', None) if g else None if has_request_context and g and g.desires_auth and not g.is_api_or_xhr: loggedin = cache.get(LOGGED_IN_CACHE_KEY) or {} loggedout = cache.get(LOGGED_OUT_CACHE_KEY) or {} g.loggedin_chat = cache.get('loggedin_chat') or 0 - g.loggedin_orgy = cache.get('loggedin_orgy') or 0 timestamp = int(time.time()) diff --git a/files/templates/header.html b/files/templates/header.html index d3d8d36ee..0ab19129e 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -225,25 +225,15 @@ {%- if FEATURES['CHAT'] -%} - {%- if v and v.allowed_in_chat and get_orgy() -%} - - {%- else -%} - - {%- endif -%} + {%- endif -%} {% endif %}
  • - {% if request.path in ['/chat', '/orgy'] %} + {% if request.path == '/chat' %}
    Users Online




    diff --git a/files/templates/mobile_navigation_bar.html b/files/templates/mobile_navigation_bar.html index c44f83395..dbd0a0970 100644 --- a/files/templates/mobile_navigation_bar.html +++ b/files/templates/mobile_navigation_bar.html @@ -47,25 +47,20 @@ {% if v %} {%- if FEATURES['CHAT'] -%} - {%- if v and v.allowed_in_chat and get_orgy() -%} - - {%- else -%} - - {%- endif -%} + {%- endif -%} {%- if FEATURES['AWARDS'] -%} diff --git a/files/templates/orgy.html b/files/templates/orgy.html index 065368036..a829ba94e 100644 --- a/files/templates/orgy.html +++ b/files/templates/orgy.html @@ -1,5 +1,5 @@ {%- extends 'root.html' -%} -{% block pagetitle -%}Orgy{%- endblock %} +{% block pagetitle -%}Chat{%- endblock %} {% block pagetype %}chat{% endblock %} {% block body_attributes %}class="has_header"{% endblock %} {% block body %} diff --git a/nginx.conf b/nginx.conf index 575418661..b55081a56 100644 --- a/nginx.conf +++ b/nginx.conf @@ -24,10 +24,7 @@ server { proxy_pass http://localhost:5001/chat; include includes/headers; } - location /orgy { - proxy_pass http://localhost:5001/orgy; - include includes/headers; - } + location =/offline.html { alias /d/files/templates/errors/offline.html; include includes/headers;