mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-30 18:33:13 +03:00
Start using the new Sender and Chat Getter interface
This commit is contained in:
parent
f0654a0833
commit
c914a92dcf
|
@ -131,27 +131,12 @@ class CallbackQuery(EventBuilder, _custom.chatgetter.ChatGetter, _custom.senderg
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chat = await self.get_input_chat() if self.is_channel else None
|
self._message = await self._client.get_messages(self.chat, ids=self._message_id)
|
||||||
self._message = await self._client.get_messages(
|
|
||||||
chat, ids=self._message_id)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return
|
return
|
||||||
|
|
||||||
return self._message
|
return self._message
|
||||||
|
|
||||||
async def _refetch_sender(self):
|
|
||||||
self._sender = self._entities.get(self.sender_id)
|
|
||||||
if not self._sender:
|
|
||||||
return
|
|
||||||
|
|
||||||
self._input_sender = utils.get_input_peer(self._chat)
|
|
||||||
if not getattr(self._input_sender, 'access_hash', True):
|
|
||||||
# getattr with True to handle the InputPeerSelf() case
|
|
||||||
m = await self.get_message()
|
|
||||||
if m:
|
|
||||||
self._sender = m._sender
|
|
||||||
self._input_sender = m._input_sender
|
|
||||||
|
|
||||||
async def answer(
|
async def answer(
|
||||||
self, message=None, cache_time=0, *, url=None, alert=False):
|
self, message=None, cache_time=0, *, url=None, alert=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -104,10 +104,6 @@ class UserUpdate(EventBuilder, _custom.chatgetter.ChatGetter, _custom.sendergett
|
||||||
"""Alias for `input_sender <telethon.tl.custom.sendergetter.SenderGetter.input_sender>`."""
|
"""Alias for `input_sender <telethon.tl.custom.sendergetter.SenderGetter.input_sender>`."""
|
||||||
return self.input_sender
|
return self.input_sender
|
||||||
|
|
||||||
async def get_input_user(self):
|
|
||||||
"""Alias for `get_input_sender <telethon.tl.custom.sendergetter.SenderGetter.get_input_sender>`."""
|
|
||||||
return await self.get_input_sender()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def user_id(self):
|
def user_id(self):
|
||||||
"""Alias for `sender_id <telethon.tl.custom.sendergetter.SenderGetter.sender_id>`."""
|
"""Alias for `sender_id <telethon.tl.custom.sendergetter.SenderGetter.sender_id>`."""
|
||||||
|
|
|
@ -136,7 +136,7 @@ class Entity:
|
||||||
return self.ty in (EntityType.GROUP, EntityType.MEGAGROUP)
|
return self.ty in (EntityType.GROUP, EntityType.MEGAGROUP)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_channel(self):
|
def is_broadcast(self):
|
||||||
"""
|
"""
|
||||||
``True`` if the entity is a broadcast channel or `broadcast group`_.
|
``True`` if the entity is a broadcast channel or `broadcast group`_.
|
||||||
|
|
||||||
|
|
|
@ -866,7 +866,7 @@ class Message(ChatGetter, SenderGetter):
|
||||||
"""
|
"""
|
||||||
# If the client wasn't set we can't emulate the behaviour correctly,
|
# If the client wasn't set we can't emulate the behaviour correctly,
|
||||||
# so as a best-effort simply return the chat peer.
|
# so as a best-effort simply return the chat peer.
|
||||||
if not self.out and self.is_private:
|
if not self.out and self.chat.is_user:
|
||||||
return _tl.PeerUser(self._client._session_state.user_id)
|
return _tl.PeerUser(self._client._session_state.user_id)
|
||||||
|
|
||||||
return self.peer_id
|
return self.peer_id
|
||||||
|
@ -928,7 +928,7 @@ class Message(ChatGetter, SenderGetter):
|
||||||
# Bots cannot access other bots' messages by their ID.
|
# Bots cannot access other bots' messages by their ID.
|
||||||
# However they can access them through replies...
|
# However they can access them through replies...
|
||||||
self._reply_message = await self._client.get_messages(
|
self._reply_message = await self._client.get_messages(
|
||||||
await self.get_input_chat() if self.is_channel else None,
|
self.chat,
|
||||||
ids=_tl.InputMessageReplyTo(self.id)
|
ids=_tl.InputMessageReplyTo(self.id)
|
||||||
)
|
)
|
||||||
if not self._reply_message:
|
if not self._reply_message:
|
||||||
|
@ -937,7 +937,7 @@ class Message(ChatGetter, SenderGetter):
|
||||||
# If that's the case, give it a second chance accessing
|
# If that's the case, give it a second chance accessing
|
||||||
# directly by its ID.
|
# directly by its ID.
|
||||||
self._reply_message = await self._client.get_messages(
|
self._reply_message = await self._client.get_messages(
|
||||||
self._input_chat if self.is_channel else None,
|
self.chat,
|
||||||
ids=self.reply_to.reply_to_msg_id
|
ids=self.reply_to.reply_to_msg_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1286,8 +1286,7 @@ class Message(ChatGetter, SenderGetter):
|
||||||
along with their input versions.
|
along with their input versions.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
chat = await self.get_input_chat() if self.is_channel else None
|
msg = await self._client.get_messages(self.chat, ids=self.id)
|
||||||
msg = await self._client.get_messages(chat, ids=self.id)
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return # We may not have the input chat/get message failed
|
return # We may not have the input chat/get message failed
|
||||||
if not msg:
|
if not msg:
|
||||||
|
@ -1302,9 +1301,6 @@ class Message(ChatGetter, SenderGetter):
|
||||||
self._forward = msg._forward
|
self._forward = msg._forward
|
||||||
self._action_entities = msg._action_entities
|
self._action_entities = msg._action_entities
|
||||||
|
|
||||||
async def _refetch_sender(self):
|
|
||||||
await self._reload_message()
|
|
||||||
|
|
||||||
def _set_buttons(self, chat, bot):
|
def _set_buttons(self, chat, bot):
|
||||||
"""
|
"""
|
||||||
Helper methods to set the buttons given the input sender and chat.
|
Helper methods to set the buttons given the input sender and chat.
|
||||||
|
|
|
@ -371,7 +371,7 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
# with events. Since they are methods, you know they may make an API
|
# with events. Since they are methods, you know they may make an API
|
||||||
# call, which can be expensive.
|
# call, which can be expensive.
|
||||||
chat = await event.get_chat()
|
chat = await event.get_chat()
|
||||||
if event.is_group:
|
if chat.is_group:
|
||||||
if event.out:
|
if event.out:
|
||||||
sprint('>> sent "{}" to chat {}'.format(
|
sprint('>> sent "{}" to chat {}'.format(
|
||||||
event.text, get_display_name(chat)
|
event.text, get_display_name(chat)
|
||||||
|
|
|
@ -78,7 +78,7 @@ async def handler(event):
|
||||||
# and we said "save pic" in the message
|
# and we said "save pic" in the message
|
||||||
if event.out and event.is_reply and 'save pic' in event.raw_text:
|
if event.out and event.is_reply and 'save pic' in event.raw_text:
|
||||||
reply_msg = await event.get_reply_message()
|
reply_msg = await event.get_reply_message()
|
||||||
replied_to_user = await reply_msg.get_input_sender()
|
replied_to_user = reply_msg.sender
|
||||||
|
|
||||||
message = await event.reply('Downloading your profile photo...')
|
message = await event.reply('Downloading your profile photo...')
|
||||||
file = await client.download_profile_photo(replied_to_user)
|
file = await client.download_profile_photo(replied_to_user)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user