diff --git a/compiler/error/source/400_BAD_REQUEST.tsv b/compiler/error/source/400_BAD_REQUEST.tsv index 3ef57b83..382e521e 100644 --- a/compiler/error/source/400_BAD_REQUEST.tsv +++ b/compiler/error/source/400_BAD_REQUEST.tsv @@ -67,4 +67,5 @@ USER_NOT_MUTUAL_CONTACT The user is not a mutual contact USER_CHANNELS_TOO_MUCH The user is already in too many channels or supergroups API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side USER_NOT_PARTICIPANT The user is not a member of this chat -CHANNEL_PRIVATE The channel/supergroup is not accessible \ No newline at end of file +CHANNEL_PRIVATE The channel/supergroup is not accessible +MESSAGE_IDS_EMPTY The requested message doesn't exist \ No newline at end of file diff --git a/docs/source/start/Installation.rst b/docs/source/start/Installation.rst index e7b2eb3d..37fedbdf 100644 --- a/docs/source/start/Installation.rst +++ b/docs/source/start/Installation.rst @@ -82,7 +82,7 @@ If no error shows up you are good to go. >>> import pyrogram >>> pyrogram.__version__ - '0.9.0' + '0.9.1' .. _TgCrypto: https://docs.pyrogram.ml/resources/TgCrypto .. _develop: http://github.com/pyrogram/pyrogram diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index 2f5981e0..4f9866e0 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -23,7 +23,7 @@ __copyright__ = "Copyright (C) 2017-2018 Dan Tès . import logging -import time from base64 import b64decode, b64encode from struct import pack from weakref import proxy -from pyrogram.api.errors import FloodWait from pyrogram.client import types as pyrogram_types from ...api import types, functions -from ...api.errors import StickersetInvalid +from ...api.errors import StickersetInvalid, MessageIdsEmpty log = logging.getLogger(__name__) @@ -215,7 +213,7 @@ def parse_channel_chat(channel: types.Channel) -> pyrogram_types.Chat: title=channel.title, username=getattr(channel, "username", None), photo=parse_chat_photo(getattr(channel, "photo", None)), - restriction_reason=getattr(channel, "restriction_reason") + restriction_reason=getattr(channel, "restriction_reason", None) ) @@ -635,19 +633,14 @@ def parse_messages( m.caption.init(m._client, m.caption_entities or []) if message.reply_to_msg_id and replies: - while True: - try: - m.reply_to_message = client.get_messages( - m.chat.id, - reply_to_message_ids=message.id, - replies=replies - 1 - ) - except FloodWait as e: - log.warning("get_messages flood: waiting {} seconds".format(e.x)) - time.sleep(e.x) - continue - else: - break + try: + m.reply_to_message = client.get_messages( + m.chat.id, + reply_to_message_ids=message.id, + replies=replies - 1 + ) + except MessageIdsEmpty: + m.reply_to_message = None elif isinstance(message, types.MessageService): action = message.action @@ -748,19 +741,11 @@ def parse_messages( ) if isinstance(action, types.MessageActionPinMessage): - while True: - try: - m.pinned_message = client.get_messages( - m.chat.id, - reply_to_message_ids=message.id, - replies=0 - ) - except FloodWait as e: - log.warning("get_messages flood: waiting {} seconds".format(e.x)) - time.sleep(e.x) - continue - else: - break + m.pinned_message = client.get_messages( + m.chat.id, + reply_to_message_ids=message.id, + replies=0 + ) else: m = pyrogram_types.Message(message_id=message.id, client=proxy(client)) @@ -973,6 +958,7 @@ def parse_chat_members(members: types.channels.ChannelParticipants or types.mess parsed_members = [] if isinstance(members, types.channels.ChannelParticipants): + count = members.count members = members.participants for member in members: @@ -1031,7 +1017,7 @@ def parse_chat_members(members: types.channels.ChannelParticipants or types.mess parsed_members.append(chat_member) return pyrogram_types.ChatMembers( - total_count=members.count, + total_count=count, chat_members=parsed_members ) else: diff --git a/pyrogram/client/types/bots/inline_keyboard_button.py b/pyrogram/client/types/bots/inline_keyboard_button.py index 0f4779a9..3d6c7b6b 100644 --- a/pyrogram/client/types/bots/inline_keyboard_button.py +++ b/pyrogram/client/types/bots/inline_keyboard_button.py @@ -31,7 +31,7 @@ class InlineKeyboardButton(Object): text (``str``): Label text on the button. - callback_data (``str``, *optional*): + callback_data (``bytes``, *optional*): Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes. url (``str``, *optional*): @@ -59,7 +59,7 @@ class InlineKeyboardButton(Object): def __init__( self, text: str, - callback_data: str = None, + callback_data: bytes = None, url: str = None, switch_inline_query: str = None, switch_inline_query_current_chat: str = None, @@ -85,7 +85,7 @@ class InlineKeyboardButton(Object): if isinstance(b, KeyboardButtonCallback): return InlineKeyboardButton( text=b.text, - callback_data=b.data.decode() + callback_data=b.data ) if isinstance(b, KeyboardButtonSwitchInline): @@ -102,7 +102,7 @@ class InlineKeyboardButton(Object): def write(self): if self.callback_data: - return KeyboardButtonCallback(self.text, self.callback_data.encode()) + return KeyboardButtonCallback(self.text, self.callback_data) if self.url: return KeyboardButtonUrl(self.text, self.url)