MarseyWorld/files/routes/chat.py

31 lines
665 B
Python
Raw Normal View History

2022-03-19 22:33:00 +00:00
from time import gmtime, strftime
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 22:16:13 +00:00
2022-03-19 22:27:34 +00:00
sex = SocketIO(app)
2022-03-19 22:16:13 +00:00
@app.get("/chat")
@auth_required
def chat( v):
return render_template("chat.html", v=v)
@sex.on('speak')
2022-03-19 22:27:34 +00:00
@auth_required
2022-03-19 22:16:13 +00:00
def speak(data, v):
2022-03-19 22:30:04 +00:00
text = sanitize(data['text'][:1000].strip())
2022-03-19 22:16:13 +00:00
data={
"avatar": v.profile_url,
"username":v.username,
"text":text,
2022-03-19 22:33:00 +00:00
"time": strftime("%d %b %Y at %H:%M:%S", gmtime(int(time.time()))),
2022-03-19 22:16:13 +00:00
"userlink":v.url
}
emit('speak', data)