sanitizing chat messages and added meme arrow greentext
This commit is contained in:
parent
e434f8277a
commit
d4b6c14e23
18
events.py
18
events.py
|
@ -4,8 +4,11 @@ SocketIO events.
|
|||
"""
|
||||
import time
|
||||
|
||||
import bleach
|
||||
from flask_socketio import SocketIO, emit, join_room
|
||||
|
||||
import database as db
|
||||
|
||||
socketio = SocketIO()
|
||||
|
||||
@socketio.on('joined', namespace="/chat")
|
||||
|
@ -29,4 +32,17 @@ def text(data):
|
|||
date = int(time.time())
|
||||
data["date"] = date
|
||||
|
||||
emit('message', data, room=room)
|
||||
message = message.strip()
|
||||
if not message:
|
||||
return
|
||||
tags = ["b", "code", "i", "s"]
|
||||
message = bleach.clean(message, tags=tags)
|
||||
lines = []
|
||||
for line in message.splitlines():
|
||||
if line.startswith(">"):
|
||||
line = '<span class="greenText">' + line + '</span>'
|
||||
lines.append(line)
|
||||
message = "<br />".join(lines)
|
||||
data["message"] = message
|
||||
|
||||
emit("message", data, room=room)
|
||||
|
|
|
@ -34,3 +34,7 @@
|
|||
resize: none;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.greenText {
|
||||
color: green;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user