2022-03-19 22:35:46 +00:00
|
|
|
import time
|
2022-03-19 22:29:28 +00:00
|
|
|
from files.helpers.wrappers import auth_required
|
|
|
|
from files.helpers.sanitize import sanitize
|
2022-03-19 22:16:13 +00:00
|
|
|
from datetime import datetime
|
2022-03-19 22:29:28 +00:00
|
|
|
from flask_socketio import SocketIO, emit
|
2022-03-19 22:30:39 +00:00
|
|
|
from files.__main__ import app
|
2022-03-19 22:31:10 +00:00
|
|
|
from flask import render_template
|
2022-03-19 23:27:39 +00:00
|
|
|
import sys
|
2022-03-19 22:16:13 +00:00
|
|
|
|
2022-03-19 23:27:39 +00:00
|
|
|
if "load_chat" in sys.argv:
|
2022-03-19 23:31:04 +00:00
|
|
|
sex = SocketIO(app)
|
2022-03-19 22:16:13 +00:00
|
|
|
|
2022-03-19 23:27:39 +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-19 23:27:39 +00:00
|
|
|
@sex.on('speak')
|
|
|
|
@auth_required
|
|
|
|
def speak(data, v):
|
2022-03-19 22:16:13 +00:00
|
|
|
|
2022-03-19 23:27:39 +00:00
|
|
|
data={
|
|
|
|
"avatar": v.profile_url,
|
|
|
|
"username":v.username,
|
|
|
|
"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-19 23:27:39 +00:00
|
|
|
emit('speak', data)
|
|
|
|
return '', 204
|