The Message Module

class crh_botnet.message.Message(msg: str)

This class contains the implementation of a message that a robot sends.

__init__(msg: str)
Parameters

msg – A string for sending. It is set to be the message’s content.

content

The message content, str

sender

ID of the message sender, int

time_created

Creation time of the message. datetime.datetime.

recipient

ID of the recipient of the message, int

set_sender(sender)
Parameters

sender (int) – The sender’s id

Returns

None

set_recipient(recipient)
Parameters

recipient (int) – The recipient’s ID or special value -1 indicating that the message should be broadcast.

Returns

None

classmethod from_json(msg: str)
Parameters

msg (str) – A JSON serialized message.

Returns

The message.

Return type

Message

classmethod from_dict(d: dict)
Parameters

d (dict) – The message

Returns

The message.

Return type

Message

classmethod from_db_record(record)
Parameters

record (sqlite3.Row) – A message retrieved from db.

Returns

The message.

Return type

Message

to_json()
Returns

The JSON serialization of the message.

Return type

str

to_dict()
Returns

The message as a JSON serializable dict.

Return type

dict

validate()

Check if the message is valid.

Return type

bool