remove /admin/chat for being unused and redundant to /contact
parent
ae939cb827
commit
1529e70abd
|
@ -2,7 +2,7 @@ import atexit
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from flask_socketio import SocketIO, emit, join_room, leave_room
|
from flask_socketio import SocketIO, emit
|
||||||
|
|
||||||
from files.helpers.actions import *
|
from files.helpers.actions import *
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
|
@ -20,17 +20,11 @@ socketio = SocketIO(
|
||||||
async_mode='gevent',
|
async_mode='gevent',
|
||||||
)
|
)
|
||||||
|
|
||||||
typing = {
|
typing = []
|
||||||
f'{SITE_FULL}/chat': [],
|
|
||||||
f'{SITE_FULL}/admin/chat': []
|
|
||||||
}
|
|
||||||
online = []
|
online = []
|
||||||
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
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}/admin/chat': {}
|
|
||||||
}
|
|
||||||
|
|
||||||
@app.get("/chat")
|
@app.get("/chat")
|
||||||
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
@limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID)
|
||||||
|
@ -38,19 +32,11 @@ messages = cache.get(f'messages') or {
|
||||||
def chat(v):
|
def chat(v):
|
||||||
if not v.admin_level and TRUESCORE_CHAT_MINIMUM and v.truescore < TRUESCORE_CHAT_MINIMUM:
|
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!")
|
abort(403, f"Need at least {TRUESCORE_CHAT_MINIMUM} truescore for access to chat!")
|
||||||
return render_template("chat.html", v=v, messages=messages[f"{SITE_FULL}/chat"])
|
return render_template("chat.html", v=v, messages=messages)
|
||||||
|
|
||||||
@app.get("/admin/chat")
|
|
||||||
@admin_level_required(2)
|
|
||||||
def admin_chat(v):
|
|
||||||
return render_template("chat.html", v=v, messages=messages[f"{SITE_FULL}/admin/chat"])
|
|
||||||
|
|
||||||
@socketio.on('speak')
|
@socketio.on('speak')
|
||||||
@admin_level_required(PERMS['CHAT'])
|
@admin_level_required(PERMS['CHAT'])
|
||||||
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'
|
||||||
|
@ -93,20 +79,20 @@ def speak(data, v):
|
||||||
emit("online", [online, muted], broadcast=True)
|
emit("online", [online, muted], broadcast=True)
|
||||||
|
|
||||||
if not self_only:
|
if not self_only:
|
||||||
identical = [x for x in list(messages[request.referrer].values())[-5:] if v.id == x['user_id'] and text == x['text']]
|
identical = [x for x in list(messages.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[request.referrer].values())[-12:] if v.id == x['user_id']])
|
count = len([x for x in list(messages.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[request.referrer].values())[-25:] if v.id == x['user_id']])
|
count = len([x for x in list(messages.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[request.referrer].get(quotes) else '',
|
"quotes": quotes if messages.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,
|
||||||
|
@ -130,45 +116,28 @@ def speak(data, v):
|
||||||
if self_only or v.shadowbanned or not execute_blackjack(v, None, text, "chat"):
|
if self_only or v.shadowbanned or not execute_blackjack(v, None, text, "chat"):
|
||||||
emit('speak', data)
|
emit('speak', data)
|
||||||
else:
|
else:
|
||||||
emit('speak', data, room=request.referrer, broadcast=True)
|
emit('speak', data, broadcast=True)
|
||||||
messages[request.referrer][id] = data
|
messages[id] = data
|
||||||
messages[request.referrer] = dict(list(messages[request.referrer].items())[-500:])
|
messages = dict(list(messages.items())[-500:])
|
||||||
|
|
||||||
typing = []
|
typing = []
|
||||||
|
|
||||||
if request.referrer == f'{SITE_FULL}/admin/chat':
|
|
||||||
title = f'New message in admin chat from @{v.username}'
|
|
||||||
notifbody = text
|
|
||||||
url = f'{SITE_FULL}/admin/chat'
|
|
||||||
|
|
||||||
admin_ids = [x[0] for x in g.db.query(User.id).filter(
|
|
||||||
User.id != v.id,
|
|
||||||
User.admin_level >= 2,
|
|
||||||
).all()]
|
|
||||||
|
|
||||||
push_notif(admin_ids, title, notifbody, url)
|
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
def refresh_online():
|
def refresh_online():
|
||||||
emit("online", [online, muted], broadcast=True)
|
emit("online", [online, muted], broadcast=True)
|
||||||
if request.referrer == f'{SITE_FULL}/chat':
|
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
||||||
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
|
||||||
|
|
||||||
@socketio.on('connect')
|
@socketio.on('connect')
|
||||||
@admin_level_required(PERMS['CHAT'])
|
@admin_level_required(PERMS['CHAT'])
|
||||||
def connect(v):
|
def connect(v):
|
||||||
if not request.referrer:
|
|
||||||
return '', 400
|
|
||||||
|
|
||||||
join_room(request.referrer)
|
|
||||||
|
|
||||||
if [v.username, v.id, v.name_color] not in online:
|
if [v.username, v.id, v.name_color] not in online:
|
||||||
online.append([v.username, v.id, v.name_color])
|
online.append([v.username, v.id, v.name_color])
|
||||||
|
|
||||||
refresh_online()
|
refresh_online()
|
||||||
|
|
||||||
emit('typing', typing[request.referrer], room=request.referrer)
|
emit('typing', typing)
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
@socketio.on('disconnect')
|
@socketio.on('disconnect')
|
||||||
|
@ -178,42 +147,29 @@ def disconnect(v):
|
||||||
online.remove([v.username, v.id, v.name_color])
|
online.remove([v.username, v.id, v.name_color])
|
||||||
refresh_online()
|
refresh_online()
|
||||||
|
|
||||||
for val in typing.values():
|
if v.username in typing:
|
||||||
if v.username in val:
|
typing.remove(v.username)
|
||||||
val.remove(v.username)
|
|
||||||
|
|
||||||
if request.referrer:
|
|
||||||
leave_room(request.referrer)
|
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
@socketio.on('typing')
|
@socketio.on('typing')
|
||||||
@admin_level_required(PERMS['CHAT'])
|
@admin_level_required(PERMS['CHAT'])
|
||||||
def typing_indicator(data, v):
|
def typing_indicator(data, v):
|
||||||
if not request.referrer:
|
if data and v.username not in typing:
|
||||||
return '', 400
|
typing.append(v.username)
|
||||||
|
elif not data and v.username in typing:
|
||||||
|
typing.remove(v.username)
|
||||||
|
|
||||||
if data and v.username not in typing[request.referrer]:
|
emit('typing', typing, broadcast=True)
|
||||||
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):
|
||||||
if not request.referrer:
|
del messages[id]
|
||||||
return '', 400
|
|
||||||
|
|
||||||
for k, val in messages[request.referrer].items():
|
emit('delete', id, broadcast=True)
|
||||||
if k == id:
|
|
||||||
del messages[request.referrer][k]
|
|
||||||
break
|
|
||||||
|
|
||||||
emit('delete', id, room=request.referrer, broadcast=True)
|
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ def api(v):
|
||||||
@app.get("/contact_us")
|
@app.get("/contact_us")
|
||||||
@app.get("/press")
|
@app.get("/press")
|
||||||
@app.get("/media")
|
@app.get("/media")
|
||||||
|
@app.get("/admin/chat")
|
||||||
@auth_desired
|
@auth_desired
|
||||||
def contact(v:Optional[User]):
|
def contact(v:Optional[User]):
|
||||||
return render_template("contact.html", v=v, msg=get_msg())
|
return render_template("contact.html", v=v, msg=get_msg())
|
||||||
|
|
|
@ -126,8 +126,6 @@ def admin_level_required(x):
|
||||||
if v.admin_level < x: abort(403)
|
if v.admin_level < x: abort(403)
|
||||||
if x and SITE != 'devrama.net' and not IS_LOCALHOST and not v.mfa_secret:
|
if x and SITE != 'devrama.net' and not IS_LOCALHOST and not v.mfa_secret:
|
||||||
abort(403, "You need to enable 2FA to use admin features!")
|
abort(403, "You need to enable 2FA to use admin features!")
|
||||||
if request.referrer == f'{SITE_FULL}/admin/chat' and v.admin_level < PERMS['CHAT']:
|
|
||||||
abort(403)
|
|
||||||
return make_response(f(*args, v=v, **kwargs))
|
return make_response(f(*args, v=v, **kwargs))
|
||||||
|
|
||||||
wrapper.__name__ = f.__name__
|
wrapper.__name__ = f.__name__
|
||||||
|
|
|
@ -4,11 +4,6 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3 class="py-2">Admin Tools</h3>
|
<h3 class="py-2">Admin Tools</h3>
|
||||||
|
|
||||||
<h4>Admin Chat</h4>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/admin/chat">Admin Chat</a></li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
{% if (v.admin_level >= PERMS['SITE_SETTINGS_SIDEBARS_BANNERS_BADGES'] or v.admin_level >= PERMS['SITE_SETTINGS_SNAPPY_QUOTES']) and (SITE_NAME == 'rDrama' or SIDEBAR_THREAD or BANNER_THREAD or BADGE_THREAD or SNAPPY_THREAD) %}
|
{% if (v.admin_level >= PERMS['SITE_SETTINGS_SIDEBARS_BANNERS_BADGES'] or v.admin_level >= PERMS['SITE_SETTINGS_SNAPPY_QUOTES']) and (SITE_NAME == 'rDrama' or SIDEBAR_THREAD or BANNER_THREAD or BADGE_THREAD or SNAPPY_THREAD) %}
|
||||||
<h4>Add Stuff</h4>
|
<h4>Add Stuff</h4>
|
||||||
<ul>
|
<ul>
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
{%- extends 'root.html' -%}
|
{%- extends 'root.html' -%}
|
||||||
{% block pagetitle -%}
|
{% block pagetitle -%}Chat{%- endblock %}
|
||||||
{%- if request.path == '/admin/chat' -%}
|
|
||||||
Admin Chat
|
|
||||||
{%- else -%}
|
|
||||||
Chat
|
|
||||||
{%- endif -%}
|
|
||||||
{%- endblock %}
|
|
||||||
{% block pagetype %}chat{% endblock %}
|
{% block pagetype %}chat{% endblock %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% include "header.html" %}
|
{% include "header.html" %}
|
||||||
|
|
|
@ -23,10 +23,6 @@ server {
|
||||||
proxy_pass http://localhost:5001/chat;
|
proxy_pass http://localhost:5001/chat;
|
||||||
include includes/headers;
|
include includes/headers;
|
||||||
}
|
}
|
||||||
location /admin/chat {
|
|
||||||
proxy_pass http://localhost:5001/admin/chat;
|
|
||||||
include includes/headers;
|
|
||||||
}
|
|
||||||
location =/offline.html {
|
location =/offline.html {
|
||||||
alias /rDrama/files/assets/offline.html;
|
alias /rDrama/files/assets/offline.html;
|
||||||
include includes/headers;
|
include includes/headers;
|
||||||
|
|
Loading…
Reference in New Issue