Titivillus/quest/events.py

38 lines
769 B
Python
Raw Normal View History

#!/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
import types
2018-08-16 15:43:43 -04:00
import bleach
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"
data = {}
2018-08-16 15:43:43 -04:00
data['message_id'] = message_id
data['message'] = message
data['date'] = date
data['name'] = name
socket.send('message', data)
events = {}
for obj in dir():
if type(locals()[obj]) == types.FunctionType:
events[locals()[obj].__name__] = locals()[obj]