mirror of
https://github.com/Xevion/tcp-chat.git
synced 2025-12-07 01:16:44 -06:00
fix order of command processing, add helper function for sending messages
This commit is contained in:
15
helpers.py
15
helpers.py
@@ -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())
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user