From e71d85c4bbb5d3574b8a13a3d0d66e63711095f4 Mon Sep 17 00:00:00 2001 From: eyMarv Date: Sun, 2 Jun 2024 11:35:24 +0200 Subject: [PATCH] Black code format + fix syntax errors Signed-off-by: eyMarv --- pyrogram/client.py | 2 +- pyrogram/dispatcher.py | 6 +- pyrogram/enums/__init__.py | 2 +- pyrogram/filters.py | 10 +-- pyrogram/handlers/message_handler.py | 14 ++-- pyrogram/methods/bots/__init__.py | 2 +- .../methods/bots/answer_pre_checkout_query.py | 4 +- .../methods/bots/get_collectible_item_info.py | 8 +-- .../methods/bots/request_callback_answer.py | 6 +- pyrogram/methods/chats/get_chat.py | 15 ++-- pyrogram/methods/decorators/__init__.py | 2 +- .../decorators/on_pre_checkout_query.py | 6 +- pyrogram/methods/messages/copy_media_group.py | 3 +- pyrogram/methods/messages/copy_message.py | 2 +- .../methods/messages/edit_message_caption.py | 4 +- .../methods/messages/edit_message_media.py | 4 +- .../methods/messages/edit_message_text.py | 2 +- .../methods/messages/get_available_effects.py | 12 ++-- pyrogram/methods/messages/send_animation.py | 8 ++- pyrogram/methods/messages/send_media_group.py | 4 +- pyrogram/methods/messages/send_photo.py | 19 ++++-- pyrogram/methods/messages/send_poll.py | 22 ++++-- pyrogram/methods/messages/send_video.py | 8 ++- pyrogram/methods/messages/stop_poll.py | 2 +- pyrogram/methods/messages/view_messages.py | 4 +- pyrogram/methods/phone/__init__.py | 4 +- pyrogram/methods/phone/get_call_members.py | 16 ++--- pyrogram/parser/markdown.py | 8 ++- pyrogram/session/session.py | 2 +- pyrogram/types/bots_and_keyboards/__init__.py | 2 +- .../collectible_item_info.py | 16 ++--- .../inline_keyboard_button.py | 65 +++++------------- .../inline_keyboard_button_buy.py | 10 +-- .../inline_keyboard_markup.py | 7 +- .../types/bots_and_keyboards/payment_info.py | 5 +- .../bots_and_keyboards/pre_checkout_query.py | 40 ++++++----- .../bots_and_keyboards/requested_chats.py | 16 +++-- .../bots_and_keyboards/shipping_address.py | 5 +- .../bots_and_keyboards/successful_payment.py | 35 ++++++---- .../messages_and_media/available_effect.py | 10 ++- pyrogram/types/messages_and_media/message.py | 68 +++++++++---------- .../messages_and_media/message_entity.py | 2 +- .../messages_and_media/message_invoice.py | 8 +-- pyrogram/types/messages_and_media/poll.py | 20 +++++- .../types/messages_and_media/poll_option.py | 11 +-- pyrogram/types/user_and_chats/chat_event.py | 8 ++- .../user_and_chats/chat_member_updated.py | 2 +- .../types/user_and_chats/group_call_member.py | 6 +- pyrogram/utils.py | 42 +++++++++--- 49 files changed, 319 insertions(+), 260 deletions(-) diff --git a/pyrogram/client.py b/pyrogram/client.py index 190f99dc5..6b1322fc6 100644 --- a/pyrogram/client.py +++ b/pyrogram/client.py @@ -50,7 +50,7 @@ BadRequest, AuthBytesInvalid, FloodWait, - FloodPremiumWait + FloodPremiumWait, ) from pyrogram.handlers.handler import Handler from pyrogram.methods import Methods diff --git a/pyrogram/dispatcher.py b/pyrogram/dispatcher.py index eddf6c960..99bbd58ac 100644 --- a/pyrogram/dispatcher.py +++ b/pyrogram/dispatcher.py @@ -219,8 +219,10 @@ async def story_parser(update, users, chats): async def pre_checkout_query_parser(update, users, chats): return ( - await pyrogram.types.PreCheckoutQuery._parse(self.client, update, users), - PreCheckoutQueryHandler + await pyrogram.types.PreCheckoutQuery._parse( + self.client, update, users + ), + PreCheckoutQueryHandler, ) async def message_bot_na_reaction_parser(update, users, chats): diff --git a/pyrogram/enums/__init__.py b/pyrogram/enums/__init__.py index 69273b79a..a8023d487 100644 --- a/pyrogram/enums/__init__.py +++ b/pyrogram/enums/__init__.py @@ -46,7 +46,7 @@ "ChatMemberStatus", "ChatMembersFilter", "ChatType", - 'ClientPlatform', + "ClientPlatform", "ListenerTypes", "MessageEntityType", "MessageMediaType", diff --git a/pyrogram/filters.py b/pyrogram/filters.py index 755a8775a..6286fe189 100644 --- a/pyrogram/filters.py +++ b/pyrogram/filters.py @@ -741,6 +741,7 @@ async def video_chat_members_invited_filter(_, __, m: Message): # endregion + # region successful_payment_filter async def successful_payment_filter(_, __, m: Message): return bool(m.successful_payment) @@ -752,6 +753,7 @@ async def successful_payment_filter(_, __, m: Message): # endregion + # region service_filter async def service_filter(_, __, m: Message): return bool(m.service) @@ -1139,11 +1141,11 @@ class topic(Filter, set): """ def __init__(self, topics: Union[int, List[int]] = None): - topics = [] if topics is None else topics if isinstance(topics, list) else [topics] - - super().__init__( - t for t in topics + topics = ( + [] if topics is None else topics if isinstance(topics, list) else [topics] ) + super().__init__(t for t in topics) + async def __call__(self, _, message: Message): return message.topic and message.topic.id in self diff --git a/pyrogram/handlers/message_handler.py b/pyrogram/handlers/message_handler.py index b8c75e81c..49705fd91 100644 --- a/pyrogram/handlers/message_handler.py +++ b/pyrogram/handlers/message_handler.py @@ -107,8 +107,10 @@ async def check(self, client: "pyrogram.Client", message: Message): :return: Whether the message has a matching listener or handler and its filters does match with the Message. """ listener_does_match = ( - await self.check_if_has_matching_listener(client, message) - )[0] if message.chat is not None and message.from_user is not None else False + (await self.check_if_has_matching_listener(client, message))[0] + if message.chat is not None and message.from_user is not None + else False + ) if callable(self.filters): if iscoroutinefunction(self.filters.__call__): @@ -135,9 +137,11 @@ async def resolve_future_or_callback( :param args: Arguments to call the callback with. :return: None """ - listener_does_match, listener = await self.check_if_has_matching_listener( - client, message - ) if message.chat is not None and message.from_user is not None else False, None + listener_does_match, listener = ( + await self.check_if_has_matching_listener(client, message) + if message.chat is not None and message.from_user is not None + else False + ), None if listener and listener_does_match: client.remove_listener(listener) diff --git a/pyrogram/methods/bots/__init__.py b/pyrogram/methods/bots/__init__.py index 7453a4cd8..e3dc46c42 100644 --- a/pyrogram/methods/bots/__init__.py +++ b/pyrogram/methods/bots/__init__.py @@ -58,6 +58,6 @@ class Bots( GetChatMenuButton, AnswerWebAppQuery, AnswerPreCheckoutQuery, - GetCollectibleItemInfo + GetCollectibleItemInfo, ): pass diff --git a/pyrogram/methods/bots/answer_pre_checkout_query.py b/pyrogram/methods/bots/answer_pre_checkout_query.py index adcd512fc..c5dd701af 100644 --- a/pyrogram/methods/bots/answer_pre_checkout_query.py +++ b/pyrogram/methods/bots/answer_pre_checkout_query.py @@ -26,7 +26,7 @@ async def answer_pre_checkout_query( self: "pyrogram.Client", pre_checkout_query_id: str, success: bool = None, - error: str = None + error: str = None, ): """Send answers to pre-checkout queries. @@ -60,6 +60,6 @@ async def answer_pre_checkout_query( raw.functions.messages.SetBotPrecheckoutResults( query_id=int(pre_checkout_query_id), success=success or None, - error=error or None + error=error or None, ) ) diff --git a/pyrogram/methods/bots/get_collectible_item_info.py b/pyrogram/methods/bots/get_collectible_item_info.py index e96f7313f..505e83897 100644 --- a/pyrogram/methods/bots/get_collectible_item_info.py +++ b/pyrogram/methods/bots/get_collectible_item_info.py @@ -23,9 +23,7 @@ class GetCollectibleItemInfo: async def get_collectible_item_info( - self: "pyrogram.Client", - username: str = None, - phone_number: str = None + self: "pyrogram.Client", username: str = None, phone_number: str = None ) -> "types.CollectibleInfo": """Returns information about a given collectible item that was purchased at https://fragment.com .. include:: /_includes/usable-by/users.rst @@ -55,9 +53,7 @@ async def get_collectible_item_info( ) r = await self.invoke( - raw.functions.fragment.GetCollectibleInfo( - collectible=input_collectible - ) + raw.functions.fragment.GetCollectibleInfo(collectible=input_collectible) ) return types.CollectibleItemInfo._parse(r) diff --git a/pyrogram/methods/bots/request_callback_answer.py b/pyrogram/methods/bots/request_callback_answer.py index 64c79ad08..27514675a 100644 --- a/pyrogram/methods/bots/request_callback_answer.py +++ b/pyrogram/methods/bots/request_callback_answer.py @@ -79,9 +79,7 @@ async def request_callback_answer( ) if password: - r = await self.invoke( - raw.functions.account.GetPassword() - ) + r = await self.invoke(raw.functions.account.GetPassword()) password = utils.compute_password_check(r, password) return await self.invoke( @@ -89,7 +87,7 @@ async def request_callback_answer( peer=await self.resolve_peer(chat_id), msg_id=message_id, data=data, - password=password + password=password, ), retries=0, timeout=timeout, diff --git a/pyrogram/methods/chats/get_chat.py b/pyrogram/methods/chats/get_chat.py index 4d466e8df..737704714 100644 --- a/pyrogram/methods/chats/get_chat.py +++ b/pyrogram/methods/chats/get_chat.py @@ -81,11 +81,15 @@ async def get_chat( if force_full: if isinstance(peer, raw.types.InputPeerChannel): - r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer)) + r = await self.invoke( + raw.functions.channels.GetFullChannel(channel=peer) + ) elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)): r = await self.invoke(raw.functions.users.GetFullUser(id=peer)) else: - r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id)) + r = await self.invoke( + raw.functions.messages.GetFullChat(chat_id=peer.chat_id) + ) return await types.Chat._parse_full(self, r) else: @@ -94,9 +98,10 @@ async def get_chat( elif isinstance(peer, (raw.types.InputPeerUser, raw.types.InputPeerSelf)): r = await self.invoke(raw.functions.users.GetUsers(id=[peer])) else: - r = await self.invoke(raw.functions.messages.GetChats(id=[peer.chat_id])) + r = await self.invoke( + raw.functions.messages.GetChats(id=[peer.chat_id]) + ) return types.Chat._parse_chat( - self, - r.chats[0] if isinstance(r, raw.types.messages.Chats) else r[0] + self, r.chats[0] if isinstance(r, raw.types.messages.Chats) else r[0] ) diff --git a/pyrogram/methods/decorators/__init__.py b/pyrogram/methods/decorators/__init__.py index 67855b2e9..8f4f4689a 100644 --- a/pyrogram/methods/decorators/__init__.py +++ b/pyrogram/methods/decorators/__init__.py @@ -60,6 +60,6 @@ class Decorators( OnStory, OnMessageReactionUpdated, OnMessageReactionCountUpdated, - OnPreCheckoutQuery + OnPreCheckoutQuery, ): pass diff --git a/pyrogram/methods/decorators/on_pre_checkout_query.py b/pyrogram/methods/decorators/on_pre_checkout_query.py index 922b213a2..c99949897 100644 --- a/pyrogram/methods/decorators/on_pre_checkout_query.py +++ b/pyrogram/methods/decorators/on_pre_checkout_query.py @@ -45,7 +45,9 @@ def on_pre_checkout_query( def decorator(func: Callable) -> Callable: if isinstance(self, pyrogram.Client): - self.add_handler(pyrogram.handlers.PreCheckoutQueryHandler(func, filters), group) + self.add_handler( + pyrogram.handlers.PreCheckoutQueryHandler(func, filters), group + ) elif isinstance(self, Filter) or self is None: if not hasattr(func, "handlers"): func.handlers = [] @@ -53,7 +55,7 @@ def decorator(func: Callable) -> Callable: func.handlers.append( ( pyrogram.handlers.PreCheckoutQueryHandler(func, self), - group if filters is None else filters + group if filters is None else filters, ) ) diff --git a/pyrogram/methods/messages/copy_media_group.py b/pyrogram/methods/messages/copy_media_group.py index 0b9e70ed9..fbfe08b4b 100644 --- a/pyrogram/methods/messages/copy_media_group.py +++ b/pyrogram/methods/messages/copy_media_group.py @@ -129,8 +129,7 @@ async def copy_media_group( file_id=file_id, has_spoiler=( has_spoilers[i] - if isinstance(has_spoilers, list) - and i < len(has_spoilers) + if isinstance(has_spoilers, list) and i < len(has_spoilers) else ( has_spoilers if isinstance(has_spoilers, bool) diff --git a/pyrogram/methods/messages/copy_message.py b/pyrogram/methods/messages/copy_message.py index f103ed3be..c52d1c37d 100644 --- a/pyrogram/methods/messages/copy_message.py +++ b/pyrogram/methods/messages/copy_message.py @@ -139,5 +139,5 @@ async def copy_message( schedule_date=schedule_date, protect_content=protect_content, invert_media=invert_media, - reply_markup=reply_markup + reply_markup=reply_markup, ) diff --git a/pyrogram/methods/messages/edit_message_caption.py b/pyrogram/methods/messages/edit_message_caption.py index e5b282d14..89f85e1ea 100644 --- a/pyrogram/methods/messages/edit_message_caption.py +++ b/pyrogram/methods/messages/edit_message_caption.py @@ -31,7 +31,7 @@ async def edit_message_caption( parse_mode: Optional["enums.ParseMode"] = None, caption_entities: List["types.MessageEntity"] = None, invert_media: bool = False, - reply_markup: "types.InlineKeyboardMarkup" = None + reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "types.Message": """Edit the caption of media messages. @@ -78,5 +78,5 @@ async def edit_message_caption( parse_mode=parse_mode, entities=caption_entities, invert_media=invert_media, - reply_markup=reply_markup + reply_markup=reply_markup, ) diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index 24427a841..f5bfce839 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -36,7 +36,7 @@ async def edit_message_media( media: "types.InputMedia", reply_markup: "types.InlineKeyboardMarkup" = None, file_name: str = None, - invert_media: bool = False + invert_media: bool = False, ) -> "types.Message": """Edit animation, audio, document, photo or video messages. @@ -278,7 +278,7 @@ async def edit_message_media( reply_markup=await reply_markup.write(self) if reply_markup else None, message=message, entities=entities, - invert_media=invert_media + invert_media=invert_media, ) ) diff --git a/pyrogram/methods/messages/edit_message_text.py b/pyrogram/methods/messages/edit_message_text.py index d2d2dea7f..ede605169 100644 --- a/pyrogram/methods/messages/edit_message_text.py +++ b/pyrogram/methods/messages/edit_message_text.py @@ -34,7 +34,7 @@ async def edit_message_text( entities: List["types.MessageEntity"] = None, disable_web_page_preview: bool = None, invert_media: bool = None, - reply_markup: "types.InlineKeyboardMarkup" = None + reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "types.Message": """Edit the text of messages. diff --git a/pyrogram/methods/messages/get_available_effects.py b/pyrogram/methods/messages/get_available_effects.py index e812c568b..8daa1ba17 100644 --- a/pyrogram/methods/messages/get_available_effects.py +++ b/pyrogram/methods/messages/get_available_effects.py @@ -29,7 +29,7 @@ class GetAvailableEffects: async def get_available_effects( - self: "pyrogram.Client" + self: "pyrogram.Client", ) -> List["types.AvailableEffect"]: """Get all available effects. @@ -44,17 +44,15 @@ async def get_available_effects( # Get all available effects await app.get_available_effects() """ - r = await self.invoke( - raw.functions.messages.GetAvailableEffects( - hash=0 - ) - ) + r = await self.invoke(raw.functions.messages.GetAvailableEffects(hash=0)) documents = {d.id: d for d in r.documents} return types.List( [ - await types.AvailableEffect._parse(self, effect, documents.get(effect.effect_sticker_id, None)) + await types.AvailableEffect._parse( + self, effect, documents.get(effect.effect_sticker_id, None) + ) for effect in r.effects ] ) diff --git a/pyrogram/methods/messages/send_animation.py b/pyrogram/methods/messages/send_animation.py index b97371d9a..d45177c6f 100644 --- a/pyrogram/methods/messages/send_animation.py +++ b/pyrogram/methods/messages/send_animation.py @@ -296,8 +296,12 @@ async def progress(current, total): noforwards=protect_content, effect=message_effect_id, invert_media=invert_media, - reply_markup=await reply_markup.write(self) if reply_markup else None, - **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) + reply_markup=( + await reply_markup.write(self) if reply_markup else None + ), + **await utils.parse_text_entities( + self, caption, parse_mode, caption_entities + ), ) if business_connection_id is not None: r = await self.invoke( diff --git a/pyrogram/methods/messages/send_media_group.py b/pyrogram/methods/messages/send_media_group.py index 40ea6f46e..7bc291480 100644 --- a/pyrogram/methods/messages/send_media_group.py +++ b/pyrogram/methods/messages/send_media_group.py @@ -61,7 +61,7 @@ async def send_media_group( schedule_date: datetime = None, protect_content: bool = None, message_effect_id: int = None, - invert_media: bool = None + invert_media: bool = None, ) -> List["types.Message"]: """Send a group of photos or videos as an album. @@ -515,7 +515,7 @@ async def send_media_group( schedule_date=utils.datetime_to_timestamp(schedule_date), noforwards=protect_content, effect=message_effect_id, - invert_media=invert_media + invert_media=invert_media, ) if business_connection_id is not None: diff --git a/pyrogram/methods/messages/send_photo.py b/pyrogram/methods/messages/send_photo.py index 20e8dadac..9d35642b3 100644 --- a/pyrogram/methods/messages/send_photo.py +++ b/pyrogram/methods/messages/send_photo.py @@ -217,10 +217,15 @@ async def send_photo( media = raw.types.InputMediaPhotoExternal( url=photo, ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, - spoiler=has_spoiler + spoiler=has_spoiler, ) else: - media = utils.get_input_media_from_file_id(photo, FileType.PHOTO, ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, has_spoiler=has_spoiler) + media = utils.get_input_media_from_file_id( + photo, + FileType.PHOTO, + ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, + has_spoiler=has_spoiler, + ) else: file = await self.save_file( photo, progress=progress, progress_args=progress_args @@ -228,7 +233,7 @@ async def send_photo( media = raw.types.InputMediaUploadedPhoto( file=file, ttl_seconds=(1 << 31) - 1 if view_once else ttl_seconds, - spoiler=has_spoiler + spoiler=has_spoiler, ) while True: @@ -243,8 +248,12 @@ async def send_photo( noforwards=protect_content, effect=message_effect_id, invert_media=invert_media, - reply_markup=await reply_markup.write(self) if reply_markup else None, - **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) + reply_markup=( + await reply_markup.write(self) if reply_markup else None + ), + **await utils.parse_text_entities( + self, caption, parse_mode, caption_entities + ), ) if business_connection_id is not None: r = await self.invoke( diff --git a/pyrogram/methods/messages/send_poll.py b/pyrogram/methods/messages/send_poll.py index 73e6d8e44..3ab8dcca9 100644 --- a/pyrogram/methods/messages/send_poll.py +++ b/pyrogram/methods/messages/send_poll.py @@ -183,19 +183,29 @@ async def send_poll( parse_mode=parse_mode, ) - solution, solution_entities = (await utils.parse_text_entities( - self, explanation, explanation_parse_mode, explanation_entities - )).values() - q, q_entities = (await pyrogram.utils.parse_text_entities(self, question, None, question_entities)).values() + solution, solution_entities = ( + await utils.parse_text_entities( + self, explanation, explanation_parse_mode, explanation_entities + ) + ).values() + q, q_entities = ( + await pyrogram.utils.parse_text_entities( + self, question, None, question_entities + ) + ).values() rpc = raw.functions.messages.SendMedia( peer=await self.resolve_peer(chat_id), media=raw.types.InputMediaPoll( poll=raw.types.Poll( id=self.rnd_id(), - question=raw.types.TextWithEntities(text=q, entities=q_entities or []), + question=raw.types.TextWithEntities( + text=q, entities=q_entities or [] + ), answers=[ - await types.PollOption(text=option.text,entities=option.entities).write(self,i) + await types.PollOption( + text=option.text, entities=option.entities + ).write(self, i) for i, option in enumerate(options) ], closed=is_closed, diff --git a/pyrogram/methods/messages/send_video.py b/pyrogram/methods/messages/send_video.py index 623c1e182..d80df488e 100644 --- a/pyrogram/methods/messages/send_video.py +++ b/pyrogram/methods/messages/send_video.py @@ -304,8 +304,12 @@ async def progress(current, total): noforwards=protect_content, effect=message_effect_id, invert_media=invert_media, - reply_markup=await reply_markup.write(self) if reply_markup else None, - **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) + reply_markup=( + await reply_markup.write(self) if reply_markup else None + ), + **await utils.parse_text_entities( + self, caption, parse_mode, caption_entities + ), ) if business_connection_id is not None: r = await self.invoke( diff --git a/pyrogram/methods/messages/stop_poll.py b/pyrogram/methods/messages/stop_poll.py index e081a449d..7d984d22d 100644 --- a/pyrogram/methods/messages/stop_poll.py +++ b/pyrogram/methods/messages/stop_poll.py @@ -68,7 +68,7 @@ async def stop_poll( id=int(poll.id), closed=True, question=raw.types.TextWithEntities(text="", entities=[]), - answers=[] + answers=[], ) ), reply_markup=await reply_markup.write(self) if reply_markup else None, diff --git a/pyrogram/methods/messages/view_messages.py b/pyrogram/methods/messages/view_messages.py index 09136f229..9fa306ef5 100644 --- a/pyrogram/methods/messages/view_messages.py +++ b/pyrogram/methods/messages/view_messages.py @@ -52,9 +52,7 @@ async def view_messages( r = await self.invoke( raw.functions.messages.GetMessagesViews( - peer=await self.resolve_peer(chat_id), - id=ids, - increment=True + peer=await self.resolve_peer(chat_id), id=ids, increment=True ) ) diff --git a/pyrogram/methods/phone/__init__.py b/pyrogram/methods/phone/__init__.py index d2cff63d9..9875e8343 100644 --- a/pyrogram/methods/phone/__init__.py +++ b/pyrogram/methods/phone/__init__.py @@ -19,7 +19,5 @@ from .get_call_members import GetCallMembers -class Phone( - GetCallMembers -): +class Phone(GetCallMembers): pass diff --git a/pyrogram/methods/phone/get_call_members.py b/pyrogram/methods/phone/get_call_members.py index 8fabc1d94..6043a9d00 100644 --- a/pyrogram/methods/phone/get_call_members.py +++ b/pyrogram/methods/phone/get_call_members.py @@ -24,9 +24,7 @@ class GetCallMembers: async def get_call_members( - self: "pyrogram.Client", - chat_id: Union[int, str], - limit: int = 0 + self: "pyrogram.Client", chat_id: Union[int, str], limit: int = 0 ) -> AsyncGenerator["types.GroupCallMember", None]: """Get the members list of a chat call. @@ -56,7 +54,9 @@ async def get_call_members( if isinstance(peer, raw.types.InputPeerChannel): r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer)) elif isinstance(peer, raw.types.InputPeerChat): - r = await self.invoke(raw.functions.messages.GetFullChat(chat_id=peer.chat_id)) + r = await self.invoke( + raw.functions.messages.GetFullChat(chat_id=peer.chat_id) + ) else: raise ValueError("Target chat should be group, supergroup or channel.") @@ -73,13 +73,9 @@ async def get_call_members( while True: r = await self.invoke( raw.functions.phone.GetGroupParticipants( - call=full_chat.call, - ids=[], - sources=[], - offset=offset, - limit=limit + call=full_chat.call, ids=[], sources=[], offset=offset, limit=limit ), - sleep_threshold=60 + sleep_threshold=60, ) users = {u.id: u for u in r.users} diff --git a/pyrogram/parser/markdown.py b/pyrogram/parser/markdown.py index bcc1bc261..af61f0e70 100644 --- a/pyrogram/parser/markdown.py +++ b/pyrogram/parser/markdown.py @@ -86,8 +86,12 @@ def blockquote_parser(self, text): result.append(line[1:].strip()) elif line.startswith(BLOCKQUOTE_EXPANDABLE_DELIM): if not in_blockquote: - line = re.sub(r'^\*\*> ', OPENING_TAG.format("blockquote expandable"), line) - line = re.sub(r'^\*\*>', OPENING_TAG.format("blockquote expandable"), line) + line = re.sub( + r"^\*\*> ", OPENING_TAG.format("blockquote expandable"), line + ) + line = re.sub( + r"^\*\*>", OPENING_TAG.format("blockquote expandable"), line + ) in_blockquote = True result.append(line.strip()) else: diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 20d79e40b..2c5385810 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -36,7 +36,7 @@ InternalServerError, AuthKeyDuplicated, FloodWait, - FloodPremiumWait + FloodPremiumWait, ServiceUnavailable, BadMsgNotification, SecurityCheckMismatch, diff --git a/pyrogram/types/bots_and_keyboards/__init__.py b/pyrogram/types/bots_and_keyboards/__init__.py index e076a0d43..b7e807807 100644 --- a/pyrogram/types/bots_and_keyboards/__init__.py +++ b/pyrogram/types/bots_and_keyboards/__init__.py @@ -93,5 +93,5 @@ "ShippingAddress", "PaymentInfo", "PreCheckoutQuery", - "SuccessfulPayment" + "SuccessfulPayment", ] diff --git a/pyrogram/types/bots_and_keyboards/collectible_item_info.py b/pyrogram/types/bots_and_keyboards/collectible_item_info.py index 66d96045d..8a98aef96 100644 --- a/pyrogram/types/bots_and_keyboards/collectible_item_info.py +++ b/pyrogram/types/bots_and_keyboards/collectible_item_info.py @@ -38,23 +38,23 @@ class CollectibleItemInfo(Object): The paid amount, in the smallest units of the cryptocurrency url (``str``): Individual URL for the item on https://fragment.com - + """ def __init__( self, *, - purchase_date : datetime, - currency : str, + purchase_date: datetime, + currency: str, amount: float, cryptocurrency: str, cryptocurrency_amount: float, - url: str + url: str, ): super().__init__() self.purchase_date = purchase_date - self.currency= currency + self.currency = currency self.amount = amount self.cryptocurrency = cryptocurrency self.cryptocurrency_amount = cryptocurrency_amount @@ -62,7 +62,7 @@ def __init__( @staticmethod def _parse( - collectible_info: "raw.types.fragment.CollectibleInfo" + collectible_info: "raw.types.fragment.CollectibleInfo", ) -> "CollectibleItemInfo": return CollectibleItemInfo( purchase_date=utils.timestamp_to_datetime(collectible_info.purchase_date), @@ -70,5 +70,5 @@ def _parse( amount=collectible_info.amount, cryptocurrency=collectible_info.crypto_currency, cryptocurrency_amount=collectible_info.crypto_amount, - url=collectible_info.url - ) \ No newline at end of file + url=collectible_info.url, + ) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py index 13105e936..1ce222297 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button.py @@ -85,7 +85,7 @@ def __init__( switch_inline_query: str = None, switch_inline_query_current_chat: str = None, callback_game: "types.CallbackGame" = None, - requires_password: Optional[bool] = None + requires_password: Optional[bool] = None, ): super().__init__() @@ -114,51 +114,32 @@ def read(b: "raw.base.KeyboardButton"): return InlineKeyboardButton( text=b.text, callback_data=data, - requires_password=getattr(b, "requires_password", None) + requires_password=getattr(b, "requires_password", None), ) if isinstance(b, raw.types.KeyboardButtonUrl): - return InlineKeyboardButton( - text=b.text, - url=b.url - ) + return InlineKeyboardButton(text=b.text, url=b.url) if isinstance(b, raw.types.KeyboardButtonUrlAuth): - return InlineKeyboardButton( - text=b.text, - login_url=types.LoginUrl.read(b) - ) + return InlineKeyboardButton(text=b.text, login_url=types.LoginUrl.read(b)) if isinstance(b, raw.types.KeyboardButtonUserProfile): - return InlineKeyboardButton( - text=b.text, - user_id=b.user_id - ) + return InlineKeyboardButton(text=b.text, user_id=b.user_id) if isinstance(b, raw.types.KeyboardButtonSwitchInline): if b.same_peer: return InlineKeyboardButton( - text=b.text, - switch_inline_query_current_chat=b.query + text=b.text, switch_inline_query_current_chat=b.query ) else: - return InlineKeyboardButton( - text=b.text, - switch_inline_query=b.query - ) + return InlineKeyboardButton(text=b.text, switch_inline_query=b.query) if isinstance(b, raw.types.KeyboardButtonGame): - return InlineKeyboardButton( - text=b.text, - callback_game=types.CallbackGame() - ) + return InlineKeyboardButton(text=b.text, callback_game=types.CallbackGame()) if isinstance(b, raw.types.KeyboardButtonWebView): return InlineKeyboardButton( - text=b.text, - web_app=types.WebAppInfo( - url=b.url - ) + text=b.text, web_app=types.WebAppInfo(url=b.url) ) if isinstance(b, raw.types.KeyboardButtonBuy): @@ -174,49 +155,37 @@ async def write(self, client: "pyrogram.Client"): ) return raw.types.KeyboardButtonCallback( - text=self.text, - data=data, - requires_password=self.requires_password + text=self.text, data=data, requires_password=self.requires_password ) if self.url is not None: - return raw.types.KeyboardButtonUrl( - text=self.text, - url=self.url - ) + return raw.types.KeyboardButtonUrl(text=self.text, url=self.url) if self.login_url is not None: return self.login_url.write( text=self.text, - bot=await client.resolve_peer(self.login_url.bot_username or "self") + bot=await client.resolve_peer(self.login_url.bot_username or "self"), ) if self.user_id is not None: return raw.types.InputKeyboardButtonUserProfile( - text=self.text, - user_id=await client.resolve_peer(self.user_id) + text=self.text, user_id=await client.resolve_peer(self.user_id) ) if self.switch_inline_query is not None: return raw.types.KeyboardButtonSwitchInline( - text=self.text, - query=self.switch_inline_query + text=self.text, query=self.switch_inline_query ) if self.switch_inline_query_current_chat is not None: return raw.types.KeyboardButtonSwitchInline( text=self.text, query=self.switch_inline_query_current_chat, - same_peer=True + same_peer=True, ) if self.callback_game is not None: - return raw.types.KeyboardButtonGame( - text=self.text - ) + return raw.types.KeyboardButtonGame(text=self.text) if self.web_app is not None: - return raw.types.KeyboardButtonWebView( - text=self.text, - url=self.web_app.url - ) + return raw.types.KeyboardButtonWebView(text=self.text, url=self.web_app.url) diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py index 3f74f2a10..25c3d4a23 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_button_buy.py @@ -18,6 +18,7 @@ from ..object import Object + class InlineKeyboardButtonBuy(Object): """One button of the inline keyboard. For simple invoice buttons. @@ -28,18 +29,13 @@ class InlineKeyboardButtonBuy(Object): the button is pressed. """ - def __init__( - self, - text: str - ): + def __init__(self, text: str): super().__init__() self.text = str(text) @staticmethod def read(b): - return InlineKeyboardButtonBuy( - text=b.text - ) + return InlineKeyboardButtonBuy(text=b.text) # TODO: Implement write method diff --git a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py index 9cb2be974..b8bfca10d 100644 --- a/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py +++ b/pyrogram/types/bots_and_keyboards/inline_keyboard_markup.py @@ -32,7 +32,12 @@ class InlineKeyboardMarkup(Object): List of button rows, each represented by a List of InlineKeyboardButton objects. """ - def __init__(self, inline_keyboard: List[List[Union["types.InlineKeyboardButton", "types.InlineKeyboardButtonBuy"]]]): + def __init__( + self, + inline_keyboard: List[ + List[Union["types.InlineKeyboardButton", "types.InlineKeyboardButtonBuy"]] + ], + ): super().__init__() self.inline_keyboard = inline_keyboard diff --git a/pyrogram/types/bots_and_keyboards/payment_info.py b/pyrogram/types/bots_and_keyboards/payment_info.py index a51b6ff04..bd170a2e7 100644 --- a/pyrogram/types/bots_and_keyboards/payment_info.py +++ b/pyrogram/types/bots_and_keyboards/payment_info.py @@ -38,11 +38,12 @@ class PaymentInfo(Object): """ def __init__( - self, *, + self, + *, name: str = None, phone_number: str = None, email: str = None, - shipping_address: "types.ShippingAddress" = None + shipping_address: "types.ShippingAddress" = None, ): super().__init__() diff --git a/pyrogram/types/bots_and_keyboards/pre_checkout_query.py b/pyrogram/types/bots_and_keyboards/pre_checkout_query.py index 71c7bb447..8a1cba568 100644 --- a/pyrogram/types/bots_and_keyboards/pre_checkout_query.py +++ b/pyrogram/types/bots_and_keyboards/pre_checkout_query.py @@ -63,7 +63,7 @@ def __init__( total_amount: int, payload: str, shipping_option_id: str = None, - payment_info: "types.PaymentInfo" = None + payment_info: "types.PaymentInfo" = None, ): super().__init__(client) @@ -76,7 +76,9 @@ def __init__( self.payment_info = payment_info @staticmethod - async def _parse(client: "pyrogram.Client", pre_checkout_query, users) -> "PreCheckoutQuery": + async def _parse( + client: "pyrogram.Client", pre_checkout_query, users + ) -> "PreCheckoutQuery": # Try to decode pre-checkout query payload into string. If that fails, fallback to bytes instead of decoding by # ignoring/replacing errors, this way, button clicks will still work. try: @@ -91,20 +93,24 @@ async def _parse(client: "pyrogram.Client", pre_checkout_query, users) -> "PreCh total_amount=pre_checkout_query.total_amount, payload=payload, shipping_option_id=pre_checkout_query.shipping_option_id, - payment_info=types.PaymentInfo( - name=pre_checkout_query.info.name, - phone_number=pre_checkout_query.info.phone, - email=pre_checkout_query.info.email, - shipping_address=types.ShippingAddress( - street_line1=pre_checkout_query.info.shipping_address.street_line1, - street_line2=pre_checkout_query.info.shipping_address.street_line2, - city=pre_checkout_query.info.shipping_address.city, - state=pre_checkout_query.info.shipping_address.state, - post_code=pre_checkout_query.info.shipping_address.post_code, - country_code=pre_checkout_query.info.shipping_address.country_iso2 + payment_info=( + types.PaymentInfo( + name=pre_checkout_query.info.name, + phone_number=pre_checkout_query.info.phone, + email=pre_checkout_query.info.email, + shipping_address=types.ShippingAddress( + street_line1=pre_checkout_query.info.shipping_address.street_line1, + street_line2=pre_checkout_query.info.shipping_address.street_line2, + city=pre_checkout_query.info.shipping_address.city, + state=pre_checkout_query.info.shipping_address.state, + post_code=pre_checkout_query.info.shipping_address.post_code, + country_code=pre_checkout_query.info.shipping_address.country_iso2, + ), ) - ) if pre_checkout_query.info else None, - client=client + if pre_checkout_query.info + else None + ), + client=client, ) async def answer(self, success: bool = None, error: str = None): @@ -134,7 +140,5 @@ async def answer(self, success: bool = None, error: str = None): Defaults to False. """ return await self._client.answer_pre_checkout_query( - pre_checkout_query_id=self.id, - success=success, - error=error + pre_checkout_query_id=self.id, success=success, error=error ) diff --git a/pyrogram/types/bots_and_keyboards/requested_chats.py b/pyrogram/types/bots_and_keyboards/requested_chats.py index cdd53aa6f..89e4e4977 100644 --- a/pyrogram/types/bots_and_keyboards/requested_chats.py +++ b/pyrogram/types/bots_and_keyboards/requested_chats.py @@ -50,11 +50,11 @@ def __init__( @staticmethod def _parse( - client, - action: Union[ - "raw.types.MessageActionRequestedPeer", - "raw.types.MessageActionRequestedPeerSentMe" - ] + client, + action: Union[ + "raw.types.MessageActionRequestedPeer", + "raw.types.MessageActionRequestedPeerSentMe", + ], ) -> "RequestedChats": _requested_chats = [] @@ -76,8 +76,10 @@ def _parse( first_name=getattr(requested_peer, "first_name", None), last_name=getattr(requested_peer, "last_name", None), username=getattr(requested_peer, "username", None), - photo=types.ChatPhoto._parse(client, getattr(requested_peer, "photo", None), peer_id, 0), - client=client + photo=types.ChatPhoto._parse( + client, getattr(requested_peer, "photo", None), peer_id, 0 + ), + client=client, ) ) diff --git a/pyrogram/types/bots_and_keyboards/shipping_address.py b/pyrogram/types/bots_and_keyboards/shipping_address.py index 14508f4ef..ed4fea141 100644 --- a/pyrogram/types/bots_and_keyboards/shipping_address.py +++ b/pyrogram/types/bots_and_keyboards/shipping_address.py @@ -44,13 +44,14 @@ class ShippingAddress(Object): """ def __init__( - self, *, + self, + *, street_line1: str, street_line2: str, city: str, state: str, post_code: str, - country_code: str + country_code: str, ): super().__init__() diff --git a/pyrogram/types/bots_and_keyboards/successful_payment.py b/pyrogram/types/bots_and_keyboards/successful_payment.py index f6b7ef01f..22449b4c9 100644 --- a/pyrogram/types/bots_and_keyboards/successful_payment.py +++ b/pyrogram/types/bots_and_keyboards/successful_payment.py @@ -49,14 +49,15 @@ class SuccessfulPayment(Object): """ def __init__( - self, *, + self, + *, currency: str, total_amount: str, payload: str, telegram_payment_charge_id: str, provider_payment_charge_id: str, shipping_option_id: str = None, - payment_info: "types.PaymentInfo" = None + payment_info: "types.PaymentInfo" = None, ): super().__init__() @@ -87,19 +88,23 @@ def _parse(client: "pyrogram.Client", successful_payment) -> "SuccessfulPayment" telegram_payment_charge_id = successful_payment.charge.id provider_payment_charge_id = successful_payment.charge.provider_charge_id shipping_option_id = successful_payment.shipping_option_id - payment_info = types.PaymentInfo( - name=successful_payment.info.name, - phone_number=successful_payment.info.phone, - email=successful_payment.info.email, - shipping_address=types.ShippingAddress( - street_line1=successful_payment.info.shipping_address.street_line1, - street_line2=successful_payment.info.shipping_address.street_line2, - city=successful_payment.info.shipping_address.city, - state=successful_payment.info.shipping_address.state, - post_code=successful_payment.info.shipping_address.post_code, - country_code=successful_payment.info.shipping_address.country_iso2 + payment_info = ( + types.PaymentInfo( + name=successful_payment.info.name, + phone_number=successful_payment.info.phone, + email=successful_payment.info.email, + shipping_address=types.ShippingAddress( + street_line1=successful_payment.info.shipping_address.street_line1, + street_line2=successful_payment.info.shipping_address.street_line2, + city=successful_payment.info.shipping_address.city, + state=successful_payment.info.shipping_address.state, + post_code=successful_payment.info.shipping_address.post_code, + country_code=successful_payment.info.shipping_address.country_iso2, + ), ) - ) if successful_payment.info else None + if successful_payment.info + else None + ) return SuccessfulPayment( currency=successful_payment.currency, @@ -108,5 +113,5 @@ def _parse(client: "pyrogram.Client", successful_payment) -> "SuccessfulPayment" telegram_payment_charge_id=telegram_payment_charge_id, provider_payment_charge_id=shipping_option_id, shipping_option_id=shipping_option_id, - payment_info=payment_info + payment_info=payment_info, ) diff --git a/pyrogram/types/messages_and_media/available_effect.py b/pyrogram/types/messages_and_media/available_effect.py index 74c05c1ca..2f123ec7b 100644 --- a/pyrogram/types/messages_and_media/available_effect.py +++ b/pyrogram/types/messages_and_media/available_effect.py @@ -58,7 +58,7 @@ def __init__( sticker: Optional["types.Sticker"] = None, is_premium: Optional[bool] = None, static_icon_id: Optional[int] = None, - effect_animation_id: Optional[int] = None + effect_animation_id: Optional[int] = None, ): super().__init__() @@ -71,7 +71,11 @@ def __init__( self.effect_animation_id = effect_animation_id @staticmethod - async def _parse(client, effect: "raw.types.AvailableEffect", document: "raw.types.Document" = None) -> "AvailableEffect": + async def _parse( + client, + effect: "raw.types.AvailableEffect", + document: "raw.types.Document" = None, + ) -> "AvailableEffect": sticker = None if document: @@ -85,5 +89,5 @@ async def _parse(client, effect: "raw.types.AvailableEffect", document: "raw.typ sticker=sticker, is_premium=getattr(effect, "premium_required", None), static_icon_id=getattr(effect, "static_icon_id", None), - effect_animation_id=getattr(effect, "effect_animation_id", None) + effect_animation_id=getattr(effect, "effect_animation_id", None), ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 93e4cb22b..7b0bbe356 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -531,8 +531,8 @@ def __init__( video_chat_ended: "types.VideoChatEnded" = None, video_chat_members_invited: "types.VideoChatMembersInvited" = None, web_app_data: "types.WebAppData" = None, - successful_payment: "types.SuccessfulPayment" = None, - gift_code: "types.GiftCode" = None, + successful_payment: "types.SuccessfulPayment" = None, + gift_code: "types.GiftCode" = None, requested_chats: "types.RequestedChats" = None, chat_ttl_period: int = None, boosts_applied: int = None, @@ -759,7 +759,7 @@ async def _parse( web_app_data = None giveaway_launched = None gift_code = None - successful_payment = None + successful_payment = None giveaway_result = None requested_chats = None chat_ttl_period = None @@ -868,7 +868,13 @@ async def _parse( elif isinstance(action, raw.types.MessageActionGiftCode): gift_code = types.GiftCode._parse(client, action, chats) service_type = enums.MessageServiceType.GIFT_CODE - elif isinstance(action, (raw.types.MessageActionRequestedPeer, raw.types.MessageActionRequestedPeerSentMe)): + elif isinstance( + action, + ( + raw.types.MessageActionRequestedPeer, + raw.types.MessageActionRequestedPeerSentMe, + ), + ): requested_chats = types.RequestedChats._parse(client, action) service_type = enums.MessageServiceType.REQUESTED_CHAT elif isinstance(action, raw.types.MessageActionSetMessagesTTL): @@ -891,7 +897,13 @@ async def _parse( elif isinstance(action, raw.types.MessageActionBoostApply): boosts_applied = action.boosts service_type = enums.MessageServiceType.BOOST_APPLY - elif isinstance(action, (raw.types.MessageActionPaymentSent, raw.types.MessageActionPaymentSentMe)): + elif isinstance( + action, + ( + raw.types.MessageActionPaymentSent, + raw.types.MessageActionPaymentSentMe, + ), + ): successful_payment = types.SuccessfulPayment._parse(client, action) service_type = enums.MessageServiceType.SUCCESSFUL_PAYMENT from_user = types.User._parse(client, users.get(user_id, None)) @@ -3008,7 +3020,7 @@ async def reply_photo( reply_to_chat_id=reply_to_chat_id, quote_text=quote_text, quote_entities=quote_entities, - view_once=view_once, + view_once=view_once, reply_markup=reply_markup, progress=progress, progress_args=progress_args, @@ -4173,7 +4185,7 @@ async def edit_text( entities: List["types.MessageEntity"] = None, disable_web_page_preview: bool = None, invert_media: bool = None, - reply_markup: "types.InlineKeyboardMarkup" = None + reply_markup: "types.InlineKeyboardMarkup" = None, ) -> "Message": """Bound method *edit_text* of :obj:`~pyrogram.types.Message`. @@ -4228,7 +4240,7 @@ async def edit_text( entities=entities, disable_web_page_preview=disable_web_page_preview, invert_media=invert_media, - reply_markup=reply_markup + reply_markup=reply_markup, ) edit = edit_text @@ -4729,7 +4741,7 @@ async def click( quote: bool = None, timeout: int = 10, request_write_access: bool = True, - password: str = None + password: str = None, ): """Bound method *click* of :obj:`~pyrogram.types.Message`. @@ -4846,29 +4858,25 @@ async def click( ) elif button.requires_password: if password is None: - raise ValueError( - "This button requires a password" - ) + raise ValueError("This button requires a password") return await self._client.request_callback_answer( chat_id=self.chat.id, message_id=self.id, callback_data=button.callback_data, password=password, - timeout=timeout + timeout=timeout, ) elif button.requires_password: if password is None: - raise ValueError( - "This button requires a password" - ) + raise ValueError("This button requires a password") return await self._client.request_callback_answer( chat_id=self.chat.id, message_id=self.id, callback_data=button.callback_data, password=password, - timeout=timeout + timeout=timeout, ) elif button.url: return button.url @@ -4876,18 +4884,13 @@ async def click( web_app = button.web_app bot_peer_id = ( - self.via_bot and - self.via_bot.id - ) or ( - self.from_user and - self.from_user.is_bot and - self.from_user.id - ) or None + (self.via_bot and self.via_bot.id) + or (self.from_user and self.from_user.is_bot and self.from_user.id) + or None + ) if not bot_peer_id: - raise ValueError( - "This button requires a bot as the sender" - ) + raise ValueError("This button requires a bot as the sender") r = await self._client.invoke( raw.functions.messages.RequestWebView( @@ -4900,10 +4903,7 @@ async def click( ) return r.url elif button.user_id: - return await self._client.get_chat( - button.user_id, - force_full=False - ) + return await self._client.get_chat(button.user_id, force_full=False) elif button.switch_inline_query: return button.switch_inline_query elif button.switch_inline_query_current_chat: @@ -5287,8 +5287,7 @@ async def read(self) -> bool: RPCError: In case of a Telegram RPC error. """ return await self._client.read_chat_history( - chat_id=self.chat.id, - max_id=self.id + chat_id=self.chat.id, max_id=self.id ) async def view(self) -> bool: @@ -5315,6 +5314,5 @@ async def view(self) -> bool: RPCError: In case of a Telegram RPC error. """ return await self._client.view_messages( - chat_id=self.chat.id, - message_id=self.id + chat_id=self.chat.id, message_id=self.id ) diff --git a/pyrogram/types/messages_and_media/message_entity.py b/pyrogram/types/messages_and_media/message_entity.py index 79a13ae06..975a077d5 100644 --- a/pyrogram/types/messages_and_media/message_entity.py +++ b/pyrogram/types/messages_and_media/message_entity.py @@ -126,7 +126,7 @@ async def write(self): if self.type not in [ enums.MessageEntityType.BLOCKQUOTE, - enums.MessageEntityType.EXPANDABLE_BLOCKQUOTE + enums.MessageEntityType.EXPANDABLE_BLOCKQUOTE, ]: args.pop("collapsed") diff --git a/pyrogram/types/messages_and_media/message_invoice.py b/pyrogram/types/messages_and_media/message_invoice.py index 847e2f807..d92363460 100644 --- a/pyrogram/types/messages_and_media/message_invoice.py +++ b/pyrogram/types/messages_and_media/message_invoice.py @@ -55,7 +55,7 @@ def __init__( self, *, title: str, - description : str, + description: str, currency: str, total_amount: int, start_parameter: str, @@ -76,9 +76,7 @@ def __init__( self.receipt_message_id = receipt_message_id @staticmethod - def _parse( - message_invoice: "raw.types.MessageMediaInvoice" - ) -> "MessageInvoice": + def _parse(message_invoice: "raw.types.MessageMediaInvoice") -> "MessageInvoice": return MessageInvoice( title=message_invoice.title, description=message_invoice.description, @@ -87,5 +85,5 @@ def _parse( start_parameter=message_invoice.start_param, shipping_address_requested=message_invoice.shipping_address_requested, test=message_invoice.test, - receipt_message_id=message_invoice.receipt_msg_id + receipt_message_id=message_invoice.receipt_msg_id, ) diff --git a/pyrogram/types/messages_and_media/poll.py b/pyrogram/types/messages_and_media/poll.py index f0c94d7a7..8579c119c 100644 --- a/pyrogram/types/messages_and_media/poll.py +++ b/pyrogram/types/messages_and_media/poll.py @@ -145,7 +145,14 @@ def _parse( if result.correct: correct_option_id = i - o_entities = [types.MessageEntity._parse(client, entity, {}) for entity in answer.text.entities] if answer.text.entities else [] + o_entities = ( + [ + types.MessageEntity._parse(client, entity, {}) + for entity in answer.text.entities + ] + if answer.text.entities + else [] + ) option_entities = types.List(filter(lambda x: x is not None, o_entities)) options.append( @@ -154,11 +161,18 @@ def _parse( voter_count=voter_count, data=answer.option, entities=option_entities, - client=client + client=client, ) ) - q_entities = [types.MessageEntity._parse(client, entity, {}) for entity in poll.question.entities] if poll.question.entities else [] + q_entities = ( + [ + types.MessageEntity._parse(client, entity, {}) + for entity in poll.question.entities + ] + if poll.question.entities + else [] + ) question_entities = types.List(filter(lambda x: x is not None, q_entities)) return Poll( diff --git a/pyrogram/types/messages_and_media/poll_option.py b/pyrogram/types/messages_and_media/poll_option.py index 62194b8f7..5590067c4 100644 --- a/pyrogram/types/messages_and_media/poll_option.py +++ b/pyrogram/types/messages_and_media/poll_option.py @@ -56,11 +56,14 @@ def __init__( self.entities = entities async def write(self, client, i): - option, entities = (await pyrogram.utils.parse_text_entities(client, self.text, None, self.entities)).values() + option, entities = ( + await pyrogram.utils.parse_text_entities( + client, self.text, None, self.entities + ) + ).values() return pyrogram.raw.types.PollAnswer( text=pyrogram.raw.types.TextWithEntities( - text=option, - entities=entities or [] + text=option, entities=entities or [] ), - option=bytes([i]) + option=bytes([i]), ) diff --git a/pyrogram/types/user_and_chats/chat_event.py b/pyrogram/types/user_and_chats/chat_event.py index f9d9c1862..7a91e0276 100644 --- a/pyrogram/types/user_and_chats/chat_event.py +++ b/pyrogram/types/user_and_chats/chat_event.py @@ -447,10 +447,14 @@ async def _parse( message = action.message if isinstance(message, raw.types.Message) and message.pinned: - pinned_message = await types.Message._parse(client, message, users, chats) + pinned_message = await types.Message._parse( + client, message, users, chats + ) action = enums.ChatEventAction.MESSAGE_PINNED elif isinstance(message, raw.types.Message) and not message.pinned: - unpinned_message = await types.Message._parse(client, message, users, chats) + unpinned_message = await types.Message._parse( + client, message, users, chats + ) action = enums.ChatEventAction.MESSAGE_UNPINNED else: action = enums.ChatEventAction.MESSAGE_PIN_CHANGED diff --git a/pyrogram/types/user_and_chats/chat_member_updated.py b/pyrogram/types/user_and_chats/chat_member_updated.py index d07fa921e..b53bc6da2 100644 --- a/pyrogram/types/user_and_chats/chat_member_updated.py +++ b/pyrogram/types/user_and_chats/chat_member_updated.py @@ -62,7 +62,7 @@ def __init__( old_chat_member: "types.ChatMember", new_chat_member: "types.ChatMember", invite_link: "types.ChatInviteLink" = None, - via_join_request: bool = None + via_join_request: bool = None, ): super().__init__(client) diff --git a/pyrogram/types/user_and_chats/group_call_member.py b/pyrogram/types/user_and_chats/group_call_member.py index 551db1024..f70c009f7 100644 --- a/pyrogram/types/user_and_chats/group_call_member.py +++ b/pyrogram/types/user_and_chats/group_call_member.py @@ -92,7 +92,7 @@ def __init__( is_video_joined: bool = None, is_hand_raised: bool = None, is_video_enabled: bool = None, - is_screen_sharing_enabled: bool = None + is_screen_sharing_enabled: bool = None, ): super().__init__(client) @@ -117,7 +117,7 @@ def _parse( client: "pyrogram.Client", member: "raw.types.GroupCallParticipant", users: Dict[int, "raw.base.User"], - chats: Dict[int, "raw.base.Chat"] + chats: Dict[int, "raw.base.Chat"], ) -> "GroupCallMember": peer = member.peer peer_id = utils.get_raw_peer_id(peer) @@ -145,5 +145,5 @@ def _parse( is_hand_raised=bool(getattr(member, "raise_hand_rating", None)), is_video_enabled=bool(getattr(member, "video", None)), is_screen_sharing_enabled=bool(getattr(member, "presentation", None)), - client=client + client=client, ) diff --git a/pyrogram/utils.py b/pyrogram/utils.py index 9d2d1abf5..6ae89b9e4 100644 --- a/pyrogram/utils.py +++ b/pyrogram/utils.py @@ -296,29 +296,55 @@ def unpack_inline_message_id( MAX_USER_ID = 999999999999 -def get_raw_peer_id(peer: Union[raw.base.Peer, raw.base.InputPeer, raw.base.RequestedPeer]) -> Optional[int]: +def get_raw_peer_id( + peer: Union[raw.base.Peer, raw.base.InputPeer, raw.base.RequestedPeer] +) -> Optional[int]: """Get the raw peer id from a Peer object""" - if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser, raw.types.RequestedPeerUser)): + if isinstance( + peer, (raw.types.PeerUser, raw.types.InputPeerUser, raw.types.RequestedPeerUser) + ): return peer.user_id - if isinstance(peer, (raw.types.PeerChat, raw.types.InputPeerChat, raw.types.RequestedPeerChat)): + if isinstance( + peer, (raw.types.PeerChat, raw.types.InputPeerChat, raw.types.RequestedPeerChat) + ): return peer.chat_id - if isinstance(peer, (raw.types.PeerChannel, raw.types.InputPeerChannel, raw.types.RequestedPeerChannel)): + if isinstance( + peer, + ( + raw.types.PeerChannel, + raw.types.InputPeerChannel, + raw.types.RequestedPeerChannel, + ), + ): return peer.channel_id return None -def get_peer_id(peer: Union[raw.base.Peer, raw.base.InputPeer, raw.base.RequestedPeer]) -> int: +def get_peer_id( + peer: Union[raw.base.Peer, raw.base.InputPeer, raw.base.RequestedPeer] +) -> int: """Get the non-raw peer id from a Peer object""" - if isinstance(peer, (raw.types.PeerUser, raw.types.InputPeerUser, raw.types.RequestedPeerUser)): + if isinstance( + peer, (raw.types.PeerUser, raw.types.InputPeerUser, raw.types.RequestedPeerUser) + ): return peer.user_id - if isinstance(peer, (raw.types.PeerChat, raw.types.InputPeerChat, raw.types.RequestedPeerChat)): + if isinstance( + peer, (raw.types.PeerChat, raw.types.InputPeerChat, raw.types.RequestedPeerChat) + ): return -peer.chat_id - if isinstance(peer, (raw.types.PeerChannel, raw.types.InputPeerChannel, raw.types.RequestedPeerChannel)): + if isinstance( + peer, + ( + raw.types.PeerChannel, + raw.types.InputPeerChannel, + raw.types.RequestedPeerChannel, + ), + ): return MAX_CHANNEL_ID - peer.channel_id raise ValueError(f"Peer type invalid: {peer}")