import struct import time from ..errors import BrokenAuthKeyError from ..extensions import BinaryReader class MtProtoPlainSender: """MTProto Mobile Protocol plain sender (https://core.telegram.org/mtproto/description#unencrypted-messages) """ def __init__(self, connection): self._sequence = 0 self._time_offset = 0 self._last_msg_id = 0 self._connection = connection def connect(self): self._connection.connect() def disconnect(self): self._connection.close() def send(self, data): """Sends a plain packet (auth_key_id = 0) containing the given message body (data) """ self._connection.send( struct.pack('= new_msg_id: new_msg_id = self._last_msg_id + 4 self._last_msg_id = new_msg_id return new_msg_id