mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 19:03:46 +03:00
Add missing checks in the message for is client None
This commit is contained in:
parent
b58c0d3071
commit
1a00de6494
|
@ -49,7 +49,7 @@ class ChatGetter(abc.ABC):
|
||||||
Note that this might not be available if the library doesn't
|
Note that this might not be available if the library doesn't
|
||||||
have enough information available.
|
have enough information available.
|
||||||
"""
|
"""
|
||||||
if self._input_chat is None and self._chat_peer:
|
if self._input_chat is None and self._chat_peer and self._client:
|
||||||
try:
|
try:
|
||||||
self._input_chat = self._client._entity_cache[self._chat_peer]
|
self._input_chat = self._client._entity_cache[self._chat_peer]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -62,7 +62,7 @@ class ChatGetter(abc.ABC):
|
||||||
Returns `input_chat`, but will make an API call to find the
|
Returns `input_chat`, but will make an API call to find the
|
||||||
input chat unless it's already cached.
|
input chat unless it's already cached.
|
||||||
"""
|
"""
|
||||||
if self.input_chat is None and self.chat_id:
|
if self.input_chat is None and self.chat_id and self._client:
|
||||||
try:
|
try:
|
||||||
# The chat may be recent, look in dialogs
|
# The chat may be recent, look in dialogs
|
||||||
target = self.chat_id
|
target = self.chat_id
|
||||||
|
|
|
@ -586,7 +586,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
|
|
||||||
The result will be cached after its first use.
|
The result will be cached after its first use.
|
||||||
"""
|
"""
|
||||||
if self._reply_message is None:
|
if self._reply_message is None and self._client:
|
||||||
if not self.reply_to_msg_id:
|
if not self.reply_to_msg_id:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -614,6 +614,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
`telethon.client.messages.MessageMethods.send_message`
|
`telethon.client.messages.MessageMethods.send_message`
|
||||||
with ``entity`` already set.
|
with ``entity`` already set.
|
||||||
"""
|
"""
|
||||||
|
if self._client:
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
await self.get_input_chat(), *args, **kwargs)
|
await self.get_input_chat(), *args, **kwargs)
|
||||||
|
|
||||||
|
@ -623,6 +624,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
`telethon.client.messages.MessageMethods.send_message`
|
`telethon.client.messages.MessageMethods.send_message`
|
||||||
with both ``entity`` and ``reply_to`` already set.
|
with both ``entity`` and ``reply_to`` already set.
|
||||||
"""
|
"""
|
||||||
|
if self._client:
|
||||||
kwargs['reply_to'] = self.id
|
kwargs['reply_to'] = self.id
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
await self.get_input_chat(), *args, **kwargs)
|
await self.get_input_chat(), *args, **kwargs)
|
||||||
|
@ -637,6 +639,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
this `forward_to` method. Use a
|
this `forward_to` method. Use a
|
||||||
`telethon.client.telegramclient.TelegramClient` instance directly.
|
`telethon.client.telegramclient.TelegramClient` instance directly.
|
||||||
"""
|
"""
|
||||||
|
if self._client:
|
||||||
kwargs['messages'] = self.id
|
kwargs['messages'] = self.id
|
||||||
kwargs['from_peer'] = await self.get_input_chat()
|
kwargs['from_peer'] = await self.get_input_chat()
|
||||||
return await self._client.forward_messages(*args, **kwargs)
|
return await self._client.forward_messages(*args, **kwargs)
|
||||||
|
@ -662,7 +665,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
This is generally the most desired and convenient behaviour,
|
This is generally the most desired and convenient behaviour,
|
||||||
and will work for link previews and message buttons.
|
and will work for link previews and message buttons.
|
||||||
"""
|
"""
|
||||||
if self.fwd_from or not self.out:
|
if self.fwd_from or not self.out or not self._client:
|
||||||
return None # We assume self.out was patched for our chat
|
return None # We assume self.out was patched for our chat
|
||||||
|
|
||||||
if 'link_preview' not in kwargs:
|
if 'link_preview' not in kwargs:
|
||||||
|
@ -688,6 +691,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
this `delete` method. Use a
|
this `delete` method. Use a
|
||||||
`telethon.client.telegramclient.TelegramClient` instance directly.
|
`telethon.client.telegramclient.TelegramClient` instance directly.
|
||||||
"""
|
"""
|
||||||
|
if self._client:
|
||||||
return await self._client.delete_messages(
|
return await self._client.delete_messages(
|
||||||
await self.get_input_chat(), [self.id],
|
await self.get_input_chat(), [self.id],
|
||||||
*args, **kwargs
|
*args, **kwargs
|
||||||
|
@ -699,6 +703,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
for `telethon.client.downloads.DownloadMethods.download_media`
|
for `telethon.client.downloads.DownloadMethods.download_media`
|
||||||
with the ``message`` already set.
|
with the ``message`` already set.
|
||||||
"""
|
"""
|
||||||
|
if self._client:
|
||||||
return await self._client.download_media(self, *args, **kwargs)
|
return await self._client.download_media(self, *args, **kwargs)
|
||||||
|
|
||||||
async def click(self, i=None, j=None,
|
async def click(self, i=None, j=None,
|
||||||
|
@ -750,6 +755,9 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
that if the message does not have this data, it will
|
that if the message does not have this data, it will
|
||||||
``raise DataInvalidError``.
|
``raise DataInvalidError``.
|
||||||
"""
|
"""
|
||||||
|
if not self._client:
|
||||||
|
return
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
if not await self.get_input_chat():
|
if not await self.get_input_chat():
|
||||||
return None
|
return None
|
||||||
|
@ -804,6 +812,9 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
Re-fetches this message to reload the sender and chat entities,
|
Re-fetches this message to reload the sender and chat entities,
|
||||||
along with their input versions.
|
along with their input versions.
|
||||||
"""
|
"""
|
||||||
|
if not self._client:
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
chat = await self.get_input_chat() if self.is_channel else None
|
chat = await self.get_input_chat() if self.is_channel else None
|
||||||
msg = await self._client.get_messages(chat, ids=self.id)
|
msg = await self._client.get_messages(chat, ids=self.id)
|
||||||
|
@ -828,7 +839,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
"""
|
"""
|
||||||
Helper methods to set the buttons given the input sender and chat.
|
Helper methods to set the buttons given the input sender and chat.
|
||||||
"""
|
"""
|
||||||
if isinstance(self.reply_markup, (
|
if self._client and isinstance(self.reply_markup, (
|
||||||
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
||||||
self._buttons = [[
|
self._buttons = [[
|
||||||
MessageButton(self._client, button, chat, bot, self.id)
|
MessageButton(self._client, button, chat, bot, self.id)
|
||||||
|
@ -844,7 +855,7 @@ class Message(ChatGetter, SenderGetter, TLObject, abc.ABC):
|
||||||
to know what bot we want to start. Raises ``ValueError`` if the bot
|
to know what bot we want to start. Raises ``ValueError`` if the bot
|
||||||
cannot be found but is needed. Returns ``None`` if it's not needed.
|
cannot be found but is needed. Returns ``None`` if it's not needed.
|
||||||
"""
|
"""
|
||||||
if not isinstance(self.reply_markup, (
|
if self._client and not isinstance(self.reply_markup, (
|
||||||
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
types.ReplyInlineMarkup, types.ReplyKeyboardMarkup)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class SenderGetter(abc.ABC):
|
||||||
Note that this might not be available if the library can't
|
Note that this might not be available if the library can't
|
||||||
find the input chat, or if the message a broadcast on a channel.
|
find the input chat, or if the message a broadcast on a channel.
|
||||||
"""
|
"""
|
||||||
if self._input_sender is None and self._sender_id:
|
if self._input_sender is None and self._sender_id and self._client:
|
||||||
try:
|
try:
|
||||||
self._input_sender = self._client.session\
|
self._input_sender = self._client.session\
|
||||||
.get_input_entity(self._sender_id)
|
.get_input_entity(self._sender_id)
|
||||||
|
@ -64,7 +64,7 @@ class SenderGetter(abc.ABC):
|
||||||
Returns `input_sender`, but will make an API call to find the
|
Returns `input_sender`, but will make an API call to find the
|
||||||
input sender unless it's already cached.
|
input sender unless it's already cached.
|
||||||
"""
|
"""
|
||||||
if self.input_sender is None and self._sender_id:
|
if self.input_sender is None and self._sender_id and self._client:
|
||||||
await self._refetch_sender()
|
await self._refetch_sender()
|
||||||
return self._input_sender
|
return self._input_sender
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user