fix order of command processing, add helper function for sending messages

This commit is contained in:
Xevion
2021-01-09 15:08:56 -06:00
parent 7c8d1c0d67
commit 1baf1b9cd9
2 changed files with 35 additions and 29 deletions

View File

@@ -1,4 +1,7 @@
import json
import time
import constants
HEADER_LENGTH = 10
@@ -17,3 +20,15 @@ def prepare_json(object) -> bytes:
:return: Encoded JSON
"""
return prepare(json.dumps(object))
def prepare_server_message(nickname: str, message: str, color: str, msgtime: int = None):
return prepare_json(
{
'type': constants.Types.MESSAGE,
'nickname': nickname,
'content': message,
'color': color,
'time': msgtime or int(time.time())
}
)