Adapt the rest of the library to layer 119

This commit is contained in:
Lonami Exo
2020-10-01 12:22:55 +02:00
parent 62737c1caf
commit d5e4398ace
14 changed files with 78 additions and 98 deletions

View File

@@ -95,7 +95,7 @@ class ChatGetter(abc.ABC):
def chat_id(self):
"""
Returns the marked chat integer ID. Note that this value **will
be different** from ``to_id`` for incoming private messages, since
be different** from ``peer_id`` for incoming private messages, since
the chat *to* which the messages go is to your own person, but
the *chat* itself is with the one who sent the message.

View File

@@ -165,7 +165,7 @@ class Conversation(ChatGetter):
"""
return self._get_message(
message, self._reply_indices, self._pending_replies, timeout,
lambda x, y: x.reply_to_msg_id == y
lambda x, y: x.reply_to and x.reply_to.reply_to_msg_id == y
)
def _get_message(
@@ -374,7 +374,7 @@ class Conversation(ChatGetter):
del self._pending_responses[msg_id]
for msg_id, future in list(self._pending_replies.items()):
if msg_id == response.reply_to_msg_id:
if response.reply_to and msg_id == response.reply_to.reply_to_msg_id:
self._reply_indices[msg_id] = len(self._incoming)
future.set_result(response)
del self._pending_replies[msg_id]

View File

@@ -1,6 +1,6 @@
from .chatgetter import ChatGetter
from .sendergetter import SenderGetter
from ... import utils
from ... import utils, helpers
from ...tl import types
@@ -30,19 +30,24 @@ class Forward(ChatGetter, SenderGetter):
self.__dict__.update(original.__dict__)
self.original_fwd = original
sender, input_sender = utils._get_entity_pair(
original.from_id, entities, client._entity_cache)
if not original.channel_id:
peer = chat = input_chat = None
sender_id = sender = input_sender = peer = chat = input_chat = None
if not original.from_id:
pass
else:
peer = types.PeerChannel(original.channel_id)
chat, input_chat = utils._get_entity_pair(
utils.get_peer_id(peer), entities, client._entity_cache)
ty = helpers._entity_type(original.from_id)
if ty == helpers._EntityType.USER:
sender_id = utils.get_peer_id(original.from_id)
sender, input_sender = utils._get_entity_pair(
sender_id, entities, client._entity_cache)
elif ty in (helpers._EntityType.CHAT, helpers._EntityType.CHANNEL):
peer = original.from_id
chat, input_chat = utils._get_entity_pair(
utils.get_peer_id(peer), entities, client._entity_cache)
# This call resets the client
ChatGetter.__init__(self, peer, chat=chat, input_chat=input_chat)
SenderGetter.__init__(self, original.from_id, sender=sender, input_sender=input_sender)
SenderGetter.__init__(self, sender_id, sender=sender, input_sender=input_sender)
self._client = client
# TODO We could reload the message

View File

@@ -85,7 +85,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
The peer who sent this message, which is either
:tl:`PeerUser`, :tl:`PeerChat` or :tl:`PeerChannel`.
reply_to (`int`):
reply_to (:tl:`MessageReplyHeader`):
The original reply header if this message is replying to another.
fwd_from (:tl:`MessageFwdHeader`):
@@ -210,15 +210,15 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
self._action_entities = None
if not out and isinstance(peer_id, types.PeerUser):
chat_peer = types.PeerUser(from_id)
if from_id == peer_id.user_id:
chat_peer = from_id
if from_id == peer_id:
self.out = not self.fwd_from # Patch out in our chat
else:
chat_peer = peer_id
# Note that these calls would reset the client
ChatGetter.__init__(self, chat_peer, broadcast=post)
SenderGetter.__init__(self, from_id)
SenderGetter.__init__(self, utils.get_peer_id(from_id) if from_id else None)
if post and not from_id and chat_peer:
# If the message comes from a Channel, let the sender be it
@@ -329,10 +329,10 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
`True` if the message is a reply to some other message.
Remember that you can access the ID of the message
this one is replying to through `reply_to_msg_id`,
this one is replying to through `reply_to.reply_to_msg_id`,
and the `Message` object with `get_reply_message()`.
"""
return bool(self.reply_to_msg_id)
return self.reply_to is not None
@property
def forward(self):
@@ -647,7 +647,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
The result will be cached after its first use.
"""
if self._reply_message is None and self._client:
if not self.reply_to_msg_id:
if not self.reply_to:
return None
# Bots cannot access other bots' messages by their ID.
@@ -663,7 +663,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
# directly by its ID.
self._reply_message = await self._client.get_messages(
self._input_chat if self.is_channel else None,
ids=self.reply_to_msg_id
ids=self.reply_to.reply_to_msg_id
)
return self._reply_message