add separate chatroom for orgies

pull/198/head
Aevann 2023-09-05 18:32:57 +03:00
parent f2ed74ec6a
commit 8bae228129
10 changed files with 100 additions and 51 deletions

View File

@ -54,7 +54,10 @@ function flash(){
else { else {
icon.href = `/i/${site_name}/icon.webp?x=6` icon.href = `/i/${site_name}/icon.webp?x=6`
notifs = 0 notifs = 0
title.innerHTML = 'Chat'; if (location.pathname == '/chat')
title.innerHTML = 'Chat';
else
title.innerHTML = 'Orgy';
} }
if (is_typing) { if (is_typing) {

View File

@ -422,7 +422,7 @@ function populate_speed_emoji_modal(results, textbox)
close_inline_speed_emoji_modal() close_inline_speed_emoji_modal()
textbox.value = textbox.value.replace(new RegExp(current_word+"(?=\\s|$)", "gi"), `:${name}: `) textbox.value = textbox.value.replace(new RegExp(current_word+"(?=\\s|$)", "gi"), `:${name}: `)
textbox.focus() textbox.focus()
if (location.pathname != '/chat'){ if (!['/chat','/orgy'].includes(location.pathname)) {
markdown(textbox) markdown(textbox)
} }
}); });

View File

@ -1973,7 +1973,7 @@ def start_orgy(v):
) )
g.db.add(orgy) g.db.add(orgy)
return {"message": "Orgy started successfully!"} return redirect('/orgy')
@app.post("/admin/stop_orgy") @app.post("/admin/stop_orgy")
@admin_level_required(PERMS['ORGIES']) @admin_level_required(PERMS['ORGIES'])

View File

@ -2,7 +2,7 @@ import atexit
import time import time
import uuid import uuid
from flask_socketio import SocketIO, emit from flask_socketio import SocketIO, emit, join_room, leave_room
from flask import request from flask import request
from files.helpers.actions import * from files.helpers.actions import *
@ -22,12 +22,23 @@ socketio = SocketIO(
async_mode='gevent', async_mode='gevent',
) )
typing = []
online = []
sessions = [] sessions = []
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
muted = cache.get(f'muted') or {} muted = cache.get(f'muted') or {}
messages = cache.get(f'messages') or {}
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(CHAT_ONLINE_CACHE_KEY, len(online[f'{SITE_FULL}/chat']), timeout=0)
def is_not_banned_socketio(f): def is_not_banned_socketio(f):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
@ -57,18 +68,33 @@ def chat(v):
if not v.allowed_in_chat: if not v.allowed_in_chat:
abort(403, CHAT_ERROR_MESSAGE) abort(403, CHAT_ERROR_MESSAGE)
displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/chat"].items() if val["user_id"] not in v.userblocks}
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)
@is_not_permabanned
def orgy(v):
if not v.allowed_in_chat:
abort(403, CHAT_ERROR_MESSAGE)
orgy = get_orgy() orgy = get_orgy()
displayed_messages = {k: val for k, val in messages.items() if val["user_id"] not in v.userblocks} if not orgy:
abort(404, "An orgy isn't currently in progress!")
if orgy: displayed_messages = {k: val for k, val in messages[f"{SITE_FULL}/orgy"].items() if val["user_id"] not in v.userblocks}
return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, site=SITE)
else: return render_template("orgy.html", v=v, messages=displayed_messages, orgy=orgy, site=SITE)
return render_template("chat.html", v=v, messages=displayed_messages)
@socketio.on('speak') @socketio.on('speak')
@is_not_banned_socketio @is_not_banned_socketio
def speak(data, v): def speak(data, v):
if not request.referrer:
return '', 400
image = None image = None
if data['file']: if data['file']:
name = f'/chat_images/{time.time()}'.replace('.','') + '.webp' name = f'/chat_images/{time.time()}'.replace('.','') + '.webp'
@ -100,30 +126,30 @@ def speak(data, v):
self_only = True self_only = True
else: else:
del muted[vname] del muted[vname]
emit("online", [online, muted], broadcast=True) emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True)
if SITE == 'rdrama.net': if SITE == 'rdrama.net':
def shut_up(): def shut_up():
self_only = True self_only = True
muted_until = int(time.time() + 600) muted_until = int(time.time() + 600)
muted[vname] = muted_until muted[vname] = muted_until
emit("online", [online, muted], broadcast=True) emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True)
if not self_only: if not self_only:
identical = [x for x in list(messages.values())[-5:] if v.id == x['user_id'] and text == x['text']] identical = [x for x in list(messages[request.referrer].values())[-5:] if v.id == x['user_id'] and text == x['text']]
if len(identical) >= 3: shut_up() if len(identical) >= 3: shut_up()
if not self_only: if not self_only:
count = len([x for x in list(messages.values())[-12:] if v.id == x['user_id']]) count = len([x for x in list(messages[request.referrer].values())[-12:] if v.id == x['user_id']])
if count >= 10: shut_up() if count >= 10: shut_up()
if not self_only: if not self_only:
count = len([x for x in list(messages.values())[-25:] if v.id == x['user_id']]) count = len([x for x in list(messages[request.referrer].values())[-25:] if v.id == x['user_id']])
if count >= 20: shut_up() if count >= 20: shut_up()
data = { data = {
"id": id, "id": id,
"quotes": quotes if messages.get(quotes) else '', "quotes": quotes if messages[request.referrer].get(quotes) else '',
"hat": v.hat_active(v)[0], "hat": v.hat_active(v)[0],
"user_id": v.id, "user_id": v.id,
"username": v.username, "username": v.username,
@ -143,41 +169,46 @@ def speak(data, v):
username = i.group(1).lower() username = i.group(1).lower()
muted_until = int(int(i.group(2)) * 60 + time.time()) muted_until = int(int(i.group(2)) * 60 + time.time())
muted[username] = muted_until muted[username] = muted_until
emit("online", [online, muted], broadcast=True) emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True)
self_only = True self_only = True
if self_only or v.shadowbanned or execute_blackjack(v, None, text, "chat"): if self_only or v.shadowbanned or execute_blackjack(v, None, text, "chat"):
emit('speak', data) emit('speak', data)
else: else:
emit('speak', data, broadcast=True) emit('speak', data, room=request.referrer, broadcast=True)
messages[id] = data messages[request.referrer][id] = data
messages = dict(list(messages.items())[-250:]) messages[request.referrer] = dict(list(messages[request.referrer].items())[-250:])
typing = [] typing = []
return '', 204 return '', 204
def refresh_online(): def refresh_online():
emit("online", [online, muted], broadcast=True) emit("online", [online[request.referrer], muted], room=request.referrer, broadcast=True)
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0) if request.referrer == f'{SITE_FULL}/chat':
cache.set(CHAT_ONLINE_CACHE_KEY, len(online[f'{SITE_FULL}/chat']), timeout=0)
@socketio.on('connect') @socketio.on('connect')
@is_not_permabanned_socketio @is_not_permabanned_socketio
def connect(v): def connect(v):
if not request.referrer:
return '', 400
if any(v.id in session for session in sessions) and [v.username, v.id, v.name_color, v.patron] not in online: join_room(request.referrer)
if any(v.id in session for session in sessions) and [v.username, v.id, v.name_color, v.patron] not in online[request.referrer]:
# user has previous running sessions with a different username or name_color # user has previous running sessions with a different username or name_color
for chat_user in online: for val in online.values():
if v.id == chat_user[1]: if [v.username, v.id, v.name_color, v.patron] in val:
online.remove(chat_user) val.remove([v.username, v.id, v.name_color, v.patron])
sessions.append([v.id, request.sid]) sessions.append([v.id, request.sid])
if [v.username, v.id, v.name_color, v.patron] not in online: if [v.username, v.id, v.name_color, v.patron] not in online[request.referrer]:
online.append([v.username, v.id, v.name_color, v.patron]) online[request.referrer].append([v.username, v.id, v.name_color, v.patron])
refresh_online() refresh_online()
emit('typing', typing) emit('typing', typing[request.referrer], room=request.referrer)
return '', 204 return '', 204
@socketio.on('disconnect') @socketio.on('disconnect')
@ -189,34 +220,48 @@ def disconnect(v):
# user has other running sessions # user has other running sessions
return '', 204 return '', 204
for chat_user in online: for val in online.values():
if v.id == chat_user[1]: if [v.username, v.id, v.name_color, v.patron] in val:
online.remove(chat_user) val.remove([v.username, v.id, v.name_color, v.patron])
if chat_user[0] in typing:
typing.remove(chat_user[0]) for val in typing.values():
if v.username in val:
val.remove(v.username)
refresh_online() refresh_online()
if request.referrer:
leave_room(request.referrer)
return '', 204 return '', 204
@socketio.on('typing') @socketio.on('typing')
@is_not_banned_socketio @is_not_banned_socketio
def typing_indicator(data, v): def typing_indicator(data, v):
if data and v.username not in typing: if not request.referrer:
typing.append(v.username) return '', 400
elif not data and v.username in typing:
typing.remove(v.username)
emit('typing', typing, broadcast=True) if data and v.username not in typing[request.referrer]:
typing[request.referrer].append(v.username)
elif not data and v.username in typing[request.referrer]:
typing[request.referrer].remove(v.username)
emit('typing', typing[request.referrer], room=request.referrer, broadcast=True)
return '', 204 return '', 204
@socketio.on('delete') @socketio.on('delete')
@admin_level_required(PERMS['POST_COMMENT_MODERATION']) @admin_level_required(PERMS['POST_COMMENT_MODERATION'])
def delete(id, v): def delete(id, v):
del messages[id] if not request.referrer:
return '', 400
emit('delete', id, broadcast=True) for k, val in messages[request.referrer].items():
if k == id:
del messages[request.referrer][k]
break
emit('delete', id, room=request.referrer, broadcast=True)
return '', 204 return '', 204

View File

@ -13,7 +13,7 @@
<div class="body d-lg-flex"> <div class="body d-lg-flex">
<div class="w-lg-100"> <div class="w-lg-100">
{% if not orgy %} {% if not orgy %}
<form id="orgy" action="/admin/start_orgy" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRReload(this)"> <form id="orgy" action="/admin/start_orgy" method="post">
<div class="d-lg-flex border-bottom"> <div class="d-lg-flex border-bottom">
<div class="title w-lg-25"> <div class="title w-lg-25">
<label for="title">Title</label> <label for="title">Title</label>

View File

@ -34,6 +34,7 @@
<input id="slurreplacer" hidden value="{{v.slurreplacer}}"> <input id="slurreplacer" hidden value="{{v.slurreplacer}}">
<input id="admin_level" hidden value="{{v.admin_level}}"> <input id="admin_level" hidden value="{{v.admin_level}}">
<input id="blocked_user_ids" hidden value="{{(v.userblocks|string)[1:-1]}}"> <input id="blocked_user_ids" hidden value="{{(v.userblocks|string)[1:-1]}}">
<link rel="stylesheet" href="{{'css/chat.css' | asset}}">
<script defer src="{{'js/vendor/socketio.js' | asset}}"></script> <script defer src="{{'js/vendor/socketio.js' | asset}}"></script>
<script defer src="{{'js/chat.js' | asset}}"></script> <script defer src="{{'js/chat.js' | asset}}"></script>
<script defer src="{{'js/vendor/lozad.js' | asset}}"></script> <script defer src="{{'js/vendor/lozad.js' | asset}}"></script>

View File

@ -391,7 +391,7 @@
</li> </li>
{% endif %} {% endif %}
<li class="mt-3"> <li class="mt-3">
{% if request.path.endswith("/chat") %} {% if request.path in ['/chat', '/orgy'] %}
<h5 class="ml-3">Users Online</h5> <h5 class="ml-3">Users Online</h5>
<div id="online3" class="col text-left d-lg-none bg-white mb-6 pb-6" style="max-width:300px"></div> <div id="online3" class="col text-left d-lg-none bg-white mb-6 pb-6" style="max-width:300px"></div>
<br><br><br><br> <br><br><br><br>

View File

@ -1,5 +1,5 @@
{%- extends 'root.html' -%} {%- extends 'root.html' -%}
{% block pagetitle -%}Chat{%- endblock %} {% block pagetitle -%}Orgy{%- endblock %}
{% block pagetype %}chat{% endblock %} {% block pagetype %}chat{% endblock %}
{% block body_attributes %}class="has_header"{% endblock %} {% block body_attributes %}class="has_header"{% endblock %}
{% block body %} {% block body %}
@ -50,6 +50,7 @@
<input id="slurreplacer" hidden value="{{v.slurreplacer}}"> <input id="slurreplacer" hidden value="{{v.slurreplacer}}">
<input id="admin_level" hidden value="{{v.admin_level}}"> <input id="admin_level" hidden value="{{v.admin_level}}">
<input id="blocked_user_ids" hidden value="{{(v.userblocks|string)[1:-1]}}"> <input id="blocked_user_ids" hidden value="{{(v.userblocks|string)[1:-1]}}">
<link rel="stylesheet" href="{{'css/chat.css' | asset}}">
<link rel="stylesheet" href="{{'css/orgy.css' | asset}}"> <link rel="stylesheet" href="{{'css/orgy.css' | asset}}">
<script defer src="{{'js/vendor/socketio.js' | asset}}"></script> <script defer src="{{'js/vendor/socketio.js' | asset}}"></script>
<script defer src="{{'js/chat.js' | asset}}"></script> <script defer src="{{'js/chat.js' | asset}}"></script>

View File

@ -136,10 +136,6 @@
<link rel="stylesheet" href="{{'events/fistmas/css/themes/dark.css'| asset}}"> <link rel="stylesheet" href="{{'events/fistmas/css/themes/dark.css'| asset}}">
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if request.path.endswith('/chat') %}
<link rel="stylesheet" href="{{'css/chat.css' | asset}}">
{% endif %}
{% endmacro %} {% endmacro %}
{% macro stylesheets_lower() %} {% macro stylesheets_lower() %}

View File

@ -20,6 +20,9 @@ server {
location /chat { location /chat {
proxy_pass http://localhost:5001/chat; proxy_pass http://localhost:5001/chat;
} }
location /orgy {
proxy_pass http://localhost:5001/orgy;
}
location =/offline.html { location =/offline.html {
alias /d/files/templates/errors/offline.html; alias /d/files/templates/errors/offline.html;
} }