diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py index 97ff3ae0e..ac24cea5d 100644 --- a/pyrogram/methods/invite_links/export_chat_invite_link.py +++ b/pyrogram/methods/invite_links/export_chat_invite_link.py @@ -29,7 +29,7 @@ async def export_chat_invite_link( self: "pyrogram.Client", chat_id: Union[int, str], subscription_period: int = None, - subscription_price: int = None + subscription_price: int = None, ) -> "types.ChatInviteLink": """Generate a new primary invite link for a chat; any previously generated primary link is revoked. @@ -71,9 +71,8 @@ async def export_chat_invite_link( peer=await self.resolve_peer(chat_id), legacy_revoke_permanent=True, subscription_pricing=raw.types.StarsSubscriptionPricing( - period=subscription_period, - amount=subscription_price - ) + period=subscription_period, amount=subscription_price + ), ) ) diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index a65c11243..eeb94d0b2 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -79,6 +79,7 @@ from .vote_poll import VotePoll from .translate_text import TranslateText + class Messages( DeleteMessages, EditMessageCaption, diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index ad98d7017..bc4b4574b 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -102,7 +102,11 @@ async def edit_message_media( message, entities = None, None if caption is not None: - message, entities = (await utils.parse_text_entities(self, caption, parse_mode, caption_entities)).values() + message, entities = ( + await utils.parse_text_entities( + self, caption, parse_mode, caption_entities + ) + ).values() if isinstance(media, types.InputMediaPhoto): if isinstance(media.media, io.BytesIO) or os.path.isfile(media.media): diff --git a/pyrogram/methods/messages/send_paid_media.py b/pyrogram/methods/messages/send_paid_media.py index 2006f8692..03effb227 100644 --- a/pyrogram/methods/messages/send_paid_media.py +++ b/pyrogram/methods/messages/send_paid_media.py @@ -34,7 +34,13 @@ async def send_paid_media( self: "pyrogram.Client", chat_id: Union[int, str], stars_amount: int, - media: List[Union["types.InputMediaAnimation", "types.InputMediaPhoto", "types.InputMediaVideo"]], + media: List[ + Union[ + "types.InputMediaAnimation", + "types.InputMediaPhoto", + "types.InputMediaVideo", + ] + ], business_connection_id: str = None, caption: str = "", caption_entities: List["types.MessageEntity"] = None, @@ -304,8 +310,7 @@ async def send_paid_media( if business_connection_id is not None: r = await self.invoke( raw.functions.InvokeWithBusinessConnection( - connection_id=business_connection_id, - query=rpc + connection_id=business_connection_id, query=rpc ) ) else: diff --git a/pyrogram/methods/messages/translate_text.py b/pyrogram/methods/messages/translate_text.py index 781a58794..abead84f2 100644 --- a/pyrogram/methods/messages/translate_text.py +++ b/pyrogram/methods/messages/translate_text.py @@ -31,7 +31,7 @@ async def translate_message_text( message_ids: Optional[Union[int, List[int]]] = None, text: Optional[str] = None, parse_mode: Optional["enums.ParseMode"] = None, - entities: Optional[List["types.MessageEntity"]] = None + entities: Optional[List["types.MessageEntity"]] = None, ) -> Union["types.TranslatedText", List["types.TranslatedText"]]: """Translates a text or message(s) to the given language. If the current user is a Telegram Premium user, then text formatting is preserved. @@ -62,12 +62,7 @@ async def translate_message_text( """ if text is not None: message, entities = ( - await utils.parse_text_entities( - self, - text, - parse_mode, - entities - ) + await utils.parse_text_entities(self, text, parse_mode, entities) ).values() r = await self.invoke( @@ -75,10 +70,9 @@ async def translate_message_text( to_lang=to_language_code, text=[ raw.types.TextWithEntities( - text=message, - entities=entities or [] + text=message, entities=entities or [] ) - ] + ], ) ) @@ -89,17 +83,16 @@ async def translate_message_text( raw.functions.messages.TranslateText( to_lang=to_language_code, peer=await self.resolve_peer(chat_id), - id=ids + id=ids, ) ) else: - raise ValueError("Either 'text' or both 'chat_id' and 'message_ids' must be provided.") + raise ValueError( + "Either 'text' or both 'chat_id' and 'message_ids' must be provided." + ) return ( types.TranslatedText._parse(self, r.result[0]) if len(r.result) == 1 - else [ - types.TranslatedText._parse(self, i) - for i in r.result - ] - ) \ No newline at end of file + else [types.TranslatedText._parse(self, i) for i in r.result] + ) diff --git a/pyrogram/methods/stickers/add_sticker_to_set.py b/pyrogram/methods/stickers/add_sticker_to_set.py index 7623aeeb6..3da666da1 100644 --- a/pyrogram/methods/stickers/add_sticker_to_set.py +++ b/pyrogram/methods/stickers/add_sticker_to_set.py @@ -79,9 +79,11 @@ async def add_sticker_to_set( user_id or "me", sticker, force_document=True, - disable_notification=True + disable_notification=True, + ) + uploaded_media = utils.get_input_media_from_file_id( + document.document.file_id, FileType.DOCUMENT ) - uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT) media = uploaded_media.id _ = await document.delete() else: @@ -95,12 +97,11 @@ async def add_sticker_to_set( if self.me.is_bot and user_id is None: raise ValueError("user_id is required for bots") document = await self.send_document( - user_id or "me", - sticker, - force_document=True, - disable_notification=True + user_id or "me", sticker, force_document=True, disable_notification=True + ) + uploaded_media = utils.get_input_media_from_file_id( + document.document.file_id, FileType.DOCUMENT ) - uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT) media = uploaded_media.id _ = await document.delete() diff --git a/pyrogram/methods/stickers/create_sticker_set.py b/pyrogram/methods/stickers/create_sticker_set.py index dd168a102..a6ed20f1f 100644 --- a/pyrogram/methods/stickers/create_sticker_set.py +++ b/pyrogram/methods/stickers/create_sticker_set.py @@ -99,9 +99,11 @@ async def create_sticker_set( user_id or "me", sticker, force_document=True, - disable_notification=True + disable_notification=True, + ) + uploaded_media = utils.get_input_media_from_file_id( + document.document.file_id, FileType.DOCUMENT ) - uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT) media = uploaded_media.id _ = await document.delete() else: @@ -113,12 +115,11 @@ async def create_sticker_set( ) else: document = await self.send_document( - user_id or "me", - sticker, - force_document=True, - disable_notification=True + user_id or "me", sticker, force_document=True, disable_notification=True + ) + uploaded_media = utils.get_input_media_from_file_id( + document.document.file_id, FileType.DOCUMENT ) - uploaded_media = utils.get_input_media_from_file_id(document.document.file_id, FileType.DOCUMENT) media = uploaded_media.id _ = await document.delete() diff --git a/pyrogram/types/bots_and_keyboards/bot_info.py b/pyrogram/types/bots_and_keyboards/bot_info.py index ba7ab8546..5ae4b2c0b 100644 --- a/pyrogram/types/bots_and_keyboards/bot_info.py +++ b/pyrogram/types/bots_and_keyboards/bot_info.py @@ -39,7 +39,9 @@ class BotInfo(Object): Privacy policy URL of the bot. """ - def __init__(self, name: str, about: str, description: str, privacy_policy_url: str = None): + def __init__( + self, name: str, about: str, description: str, privacy_policy_url: str = None + ): super().__init__() self.name = name @@ -50,8 +52,8 @@ def __init__(self, name: str, about: str, description: str, privacy_policy_url: @staticmethod def _parse(bot_info: "raw.types.bots.BotInfo") -> "BotInfo": return BotInfo( - name=getattr(bot_info,"name", None), - about=getattr(bot_info,"about", None), - description=getattr(bot_info,"description", None), - privacy_policy_url=getattr(bot_info,"privacy_policy_url", None) + name=getattr(bot_info, "name", None), + about=getattr(bot_info, "about", None), + description=getattr(bot_info, "description", None), + privacy_policy_url=getattr(bot_info, "privacy_policy_url", None), ) diff --git a/pyrogram/types/messages_and_media/giveaway.py b/pyrogram/types/messages_and_media/giveaway.py index b8c4fb4d8..f641b196b 100644 --- a/pyrogram/types/messages_and_media/giveaway.py +++ b/pyrogram/types/messages_and_media/giveaway.py @@ -64,7 +64,7 @@ def __init__( quantity: int, months: int, expire_date: datetime, - new_subscribers : bool, + new_subscribers: bool, additional_price: str = None, allowed_countries: List[str] = None, private_channel_ids: List[int] = None, @@ -107,7 +107,9 @@ async def _parse(client, message: "raw.types.Message") -> "Giveaway": expire_date=utils.timestamp_to_datetime(giveaway.until_date), new_subscribers=giveaway.only_new_subscribers, additional_price=giveaway.prize_description, - allowed_countries=giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None, + allowed_countries=( + giveaway.countries_iso2 if len(giveaway.countries_iso2) > 0 else None + ), private_channel_ids=private_ids if len(private_ids) > 0 else None, client=client, ) diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 3f61ebcf1..2365b69a1 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -560,7 +560,7 @@ def __init__( ] = None, reactions: List["types.Reaction"] = None, chat_join_type: "enums.ChatJoinType" = None, - raw: "raw.types.Message" = None + raw: "raw.types.Message" = None, ): super().__init__(client) @@ -1012,7 +1012,7 @@ async def _parse( join_request_approved=join_request_approved, raw=message, chat_join_type=chat_join_type, - client=client + client=client, # TODO: supergroup_chat_created ) if parsed_message.chat.type is not enums.ChatType.CHANNEL: @@ -5495,10 +5495,7 @@ async def pay(self) -> bool: chat_id=self.chat.id, message_id=self.id ) - async def translate( - self, - to_language_code: str - ) -> "types.TranslatedText": + async def translate(self, to_language_code: str) -> "types.TranslatedText": """Bound method *translate* of :obj:`~pyrogram.types.Message`. Use as a shortcut for: .. code-block:: python @@ -5520,7 +5517,5 @@ async def translate( RPCError: In case of a Telegram RPC error. """ return await self._client.translate_message_text( - chat_id=self.chat.id, - message_ids=self.id, - to_language_code=to_language_code + chat_id=self.chat.id, message_ids=self.id, to_language_code=to_language_code ) diff --git a/pyrogram/types/messages_and_media/translated_text.py b/pyrogram/types/messages_and_media/translated_text.py index 7215463de..4c9e5146c 100644 --- a/pyrogram/types/messages_and_media/translated_text.py +++ b/pyrogram/types/messages_and_media/translated_text.py @@ -37,19 +37,13 @@ class TranslatedText(Object): Entities of the text. """ - def __init__( - self, - *, - text: str, - entities: List["types.MessageEntity"] = None - ): + def __init__(self, *, text: str, entities: List["types.MessageEntity"] = None): self.text = text self.entities = entities @staticmethod def _parse( - client, - translate_result: "raw.types.TextWithEntities" + client, translate_result: "raw.types.TextWithEntities" ) -> "TranslatedText": entities = [ types.MessageEntity._parse(client, entity, {}) @@ -58,5 +52,6 @@ def _parse( entities = types.List(filter(lambda x: x is not None, entities)) return TranslatedText( - text=Str(translate_result.text).init(entities) or None, entities=entities or None + text=Str(translate_result.text).init(entities) or None, + entities=entities or None, ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index dee7a2d0e..9781fc9f7 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -1096,9 +1096,7 @@ async def leave(self): return await self._client.leave_chat(self.id) async def export_invite_link( - self, - subscription_period: int = None, - subscription_price: int = None + self, subscription_period: int = None, subscription_price: int = None ): """Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`. @@ -1131,7 +1129,7 @@ async def export_invite_link( return await self._client.export_chat_invite_link( self.id, subscription_period=subscription_period, - subscription_price=subscription_price + subscription_price=subscription_price, ) async def get_member( diff --git a/pyrogram/types/user_and_chats/chat_invite_link.py b/pyrogram/types/user_and_chats/chat_invite_link.py index a7a4e1c5e..5e6dfbbfe 100644 --- a/pyrogram/types/user_and_chats/chat_invite_link.py +++ b/pyrogram/types/user_and_chats/chat_invite_link.py @@ -95,7 +95,7 @@ def __init__( pending_join_request_count: int = None, subscription_expired: int = None, subscription_period: int = None, - subscription_price: int = None + subscription_price: int = None, ): super().__init__() @@ -145,6 +145,14 @@ def _parse( member_count=invite.usage, pending_join_request_count=invite.requested, subscription_expired=invite.subscription_expired, - subscription_period=subscription_pricing.period if subscription_pricing is not None else None, - subscription_price=subscription_pricing.amount if subscription_pricing is not None else None + subscription_period=( + subscription_pricing.period + if subscription_pricing is not None + else None + ), + subscription_price=( + subscription_pricing.amount + if subscription_pricing is not None + else None + ), )