MarseyWorld/files/routes/chat.py

35 lines
857 B
Python
Raw Normal View History

2022-03-20 20:41:54 +00:00
from files.helpers.const import SITE
2022-03-19 22:16:13 +00:00
2022-03-22 00:24:17 +00:00
if SITE=='pcmemes.net':
2022-03-20 20:41:54 +00:00
import time
from files.helpers.wrappers import auth_required
from files.helpers.sanitize import sanitize
from datetime import datetime
from flask_socketio import SocketIO, emit
from files.__main__ import app
from flask import render_template
import sys
2022-03-20 00:13:02 +00:00
@app.get("/chat")
@auth_required
def chat( v):
return render_template("chat.html", v=v)
2022-03-19 22:16:13 +00:00
2022-03-20 00:13:02 +00:00
sex = SocketIO(app, logger=True, engineio_logger=True, debug=True, async_mode='gevent')
2022-03-19 22:16:13 +00:00
2022-03-20 00:13:02 +00:00
@sex.on('speak')
@auth_required
def speak(data, v):
2022-03-19 23:32:41 +00:00
2022-03-20 00:13:02 +00:00
data={
"avatar": v.profile_url,
"username":v.username,
2022-03-22 00:30:20 +00:00
"namecolor":v.namecolor,
2022-03-20 00:13:02 +00:00
"text":sanitize(data[:1000].strip()),
"time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time()))),
"userlink":v.url
}
2022-03-19 22:16:13 +00:00
2022-03-20 00:13:02 +00:00
emit('speak', data, broadcast=True)
return '', 204