mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Call Chat/Sender Getter init methods
This commit is contained in:
parent
fefd6f0e6d
commit
9730894a07
|
@ -95,11 +95,9 @@ class CallbackQuery(EventBuilder):
|
|||
"""
|
||||
def __init__(self, query, peer, msg_id):
|
||||
super().__init__(peer, msg_id=msg_id)
|
||||
SenderGetter.__init__(self, query.user_id)
|
||||
self.query = query
|
||||
self.data_match = None
|
||||
self._sender_id = query.user_id
|
||||
self._input_sender = None
|
||||
self._sender = None
|
||||
self._message = None
|
||||
self._answered = False
|
||||
|
||||
|
|
|
@ -134,11 +134,10 @@ class EventCommon(ChatGetter, abc.ABC):
|
|||
_event_name = 'Event'
|
||||
|
||||
def __init__(self, chat_peer=None, msg_id=None, broadcast=False):
|
||||
super().__init__(self, chat_peer, broadcast=broadcast)
|
||||
self._entities = {}
|
||||
self._client = None
|
||||
self._chat_peer = chat_peer
|
||||
self._message_id = msg_id
|
||||
self._broadcast = broadcast
|
||||
self.original_update = None
|
||||
|
||||
def _set_client(self, client):
|
||||
|
|
|
@ -80,12 +80,10 @@ class InlineQuery(EventBuilder):
|
|||
"""
|
||||
def __init__(self, query):
|
||||
super().__init__(chat_peer=types.PeerUser(query.user_id))
|
||||
SenderGetter.__init__(self, query.user_id)
|
||||
self.query = query
|
||||
self.pattern_match = None
|
||||
self._answered = False
|
||||
self._sender_id = query.user_id
|
||||
self._input_sender = None
|
||||
self._sender = None
|
||||
|
||||
def _set_client(self, client):
|
||||
super()._set_client(client)
|
||||
|
|
|
@ -101,9 +101,7 @@ class UserUpdate(EventBuilder):
|
|||
# We need the client to actually figure out its type.
|
||||
super().__init__(chat_id)
|
||||
|
||||
self._sender_id = user_id
|
||||
self._input_sender = None
|
||||
self._sender = None
|
||||
SenderGetter.__init__(self, user_id)
|
||||
|
||||
self.online = None if status is None else \
|
||||
isinstance(status, types.UserStatusOnline)
|
||||
|
|
|
@ -9,14 +9,13 @@ class ChatGetter(abc.ABC):
|
|||
Helper base class that introduces the `chat`, `input_chat`
|
||||
and `chat_id` properties and `get_chat` and `get_input_chat`
|
||||
methods.
|
||||
|
||||
Subclasses **must** have the following private members: `_chat`,
|
||||
`_input_chat`, `_chat_peer`, `_broadcast` and `_client`. As an end
|
||||
user, you should not worry about this.
|
||||
"""
|
||||
def __init__(self):
|
||||
self._chat = self._input_chat = self._chat_peer = \
|
||||
self._client = self._broadcast = None
|
||||
def __init__(self, chat_peer=None, *, input_chat=None, chat=None, broadcast=None):
|
||||
self._chat_peer = chat_peer
|
||||
self._input_chat = input_chat
|
||||
self._chat = chat
|
||||
self._broadcast = broadcast
|
||||
self._client = None
|
||||
|
||||
@property
|
||||
def chat(self):
|
||||
|
|
|
@ -30,15 +30,13 @@ class Conversation(ChatGetter):
|
|||
def __init__(self, client, input_chat,
|
||||
*, timeout, total_timeout, max_messages,
|
||||
exclusive, replies_are_responses):
|
||||
# This call resets the client
|
||||
ChatGetter.__init__(self, input_chat=input_chat)
|
||||
|
||||
self._id = Conversation._id_counter
|
||||
Conversation._id_counter += 1
|
||||
|
||||
self._client = client
|
||||
self._chat = None
|
||||
self._input_chat = input_chat
|
||||
self._chat_peer = None
|
||||
self._broadcast = None
|
||||
|
||||
self._timeout = timeout
|
||||
self._total_timeout = total_timeout
|
||||
self._total_due = None
|
||||
|
|
|
@ -28,17 +28,17 @@ class Forward(ChatGetter, SenderGetter):
|
|||
self._client = client
|
||||
self.original_fwd = original
|
||||
|
||||
self._sender_id = original.from_id
|
||||
self._sender, self._input_sender = utils._get_entity_pair(
|
||||
sender, input_sender = utils._get_entity_pair(
|
||||
original.from_id, entities, client._entity_cache)
|
||||
|
||||
self._broadcast = None
|
||||
if original.channel_id:
|
||||
self._chat_peer = types.PeerChannel(original.channel_id)
|
||||
|
||||
self._chat, self._input_chat = utils._get_entity_pair(
|
||||
self.chat_id, entities, client._entity_cache)
|
||||
if not original.channel_id:
|
||||
peer = chat = input_chat = None
|
||||
else:
|
||||
self._chat = self._input_chat = self._chat_peer = None
|
||||
peer = types.PeerChannel(original.channel_id)
|
||||
chat, input_chat = utils._get_entity_pair(
|
||||
utils.get_peer_id(peer), entities, client._entity_cache)
|
||||
|
||||
ChatGetter.__init__(self, peer, chat=chat, input_chat=input_chat)
|
||||
SenderGetter.__init__(self, original.from_id, sender=sender, input_sender=input_sender)
|
||||
|
||||
# TODO We could reload the message
|
||||
|
|
|
@ -184,27 +184,25 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
|||
self._buttons = None
|
||||
self._buttons_flat = None
|
||||
self._buttons_count = None
|
||||
self._sender_id = from_id
|
||||
self._sender = None
|
||||
self._input_sender = None
|
||||
self._via_bot = None
|
||||
self._via_input_bot = None
|
||||
self._action_entities = None
|
||||
|
||||
if not out and isinstance(to_id, types.PeerUser):
|
||||
self._chat_peer = types.PeerUser(from_id)
|
||||
chat_peer = types.PeerUser(from_id)
|
||||
if from_id == to_id.user_id:
|
||||
self.out = not self.fwd_from # Patch out in our chat
|
||||
else:
|
||||
self._chat_peer = to_id
|
||||
chat_peer = to_id
|
||||
|
||||
if post and not from_id and self._chat_peer:
|
||||
# Note that these calls would reset the client
|
||||
ChatGetter.__init__(self, chat_peer, broadcast=post)
|
||||
SenderGetter.__init__(self, from_id)
|
||||
|
||||
if post and not from_id and chat_peer:
|
||||
# If the message comes from a Channel, let the sender be it
|
||||
self._sender_id = utils.get_peer_id(self._chat_peer)
|
||||
self._sender_id = utils.get_peer_id(chat_peer)
|
||||
|
||||
self._broadcast = post
|
||||
self._chat = None
|
||||
self._input_chat = None
|
||||
self._forward = None
|
||||
|
||||
def _finish_init(self, client, entities, input_chat):
|
||||
|
|
|
@ -6,14 +6,12 @@ class SenderGetter(abc.ABC):
|
|||
Helper base class that introduces the `sender`, `input_sender`
|
||||
and `sender_id` properties and `get_sender` and `get_input_sender`
|
||||
methods.
|
||||
|
||||
Subclasses **must** have the following private members: `_sender`,
|
||||
`_input_sender`, `_sender_id` and `_client`. As an end user, you
|
||||
should not worry about this.
|
||||
"""
|
||||
def __init__(self):
|
||||
self._sender = self._input_sender = self._sender_id = \
|
||||
self._client = None
|
||||
def __init__(self, sender_id=None, *, sender=None, input_sender=None):
|
||||
self._sender_id = sender_id
|
||||
self._sender = sender
|
||||
self._input_sender = input_sender
|
||||
self._client = None
|
||||
|
||||
@property
|
||||
def sender(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user