-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
29 lines (21 loc) · 742 Bytes
/
utils.py
File metadata and controls
29 lines (21 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
def package_msg(key, msg):
packed_msg = {}
packed_msg[key] = msg
return json.dumps(packed_msg)
def package_sys_msg(key, msg):
packed_msg = {}
packed_msg['SysMsg'] = {key: msg}
return json.dumps(packed_msg)
def package_public_chat_msg(sender, msg):
packed_msg = {}
packed_msg['ChatMsg'] = {'toAll': [sender, msg]}
return json.dumps(packed_msg)
def package_private_chat_msg(sender, receiver, msg):
packed_msg = {}
packed_msg['ChatMsg'] = {'toClient': [sender, receiver, msg]}
return json.dumps(packed_msg)
def package_room_chat_msg(sender, room_name, msg):
packed_msg = {}
packed_msg['ChatMsg'] = {'toRoom': [sender, room_name, msg]}
return json.dumps(packed_msg)