2018-08-15 17:41:51 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
"""
|
|
|
|
Individual functions for handling WebSocket events. Gets called by the
|
|
|
|
QuestConsumer object in consumers.py.
|
|
|
|
"""
|
2018-08-16 15:43:43 -04:00
|
|
|
import time
|
2018-08-15 17:41:51 -04:00
|
|
|
import types
|
|
|
|
|
2018-08-16 15:43:43 -04:00
|
|
|
import bleach
|
|
|
|
|
2018-08-15 17:41:51 -04:00
|
|
|
def message(socket, data):
|
|
|
|
"""
|
|
|
|
Gets called when the server receives a 'message' event.
|
|
|
|
"""
|
|
|
|
message = data.get('message')
|
2018-08-16 15:43:43 -04:00
|
|
|
|
|
|
|
message = message.strip()
|
|
|
|
if not message:
|
|
|
|
return
|
|
|
|
tags = ["b", "code", "i", "s"]
|
|
|
|
message = bleach.clean(message, tags=tags)
|
|
|
|
message_id = 1
|
|
|
|
date = int(time.time())
|
|
|
|
name = "Anonymous"
|
2018-08-15 17:41:51 -04:00
|
|
|
|
|
|
|
data = {}
|
2018-08-16 15:43:43 -04:00
|
|
|
data['message_id'] = message_id
|
|
|
|
data['message'] = message
|
|
|
|
data['date'] = date
|
|
|
|
data['name'] = name
|
2018-08-15 17:41:51 -04:00
|
|
|
socket.send('message', data)
|
|
|
|
|
|
|
|
|
|
|
|
events = {}
|
|
|
|
for obj in dir():
|
|
|
|
if type(locals()[obj]) == types.FunctionType:
|
|
|
|
events[locals()[obj].__name__] = locals()[obj]
|