diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index 67c8d6aba..c9bd8b8d3 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -219,6 +219,7 @@ def get_title_list(s: str) -> list: get_discussion_replies get_discussion_replies_count get_custom_emoji_stickers + translate_message_text """, chats=""" Chats @@ -510,6 +511,7 @@ def get_title_list(s: str) -> list: WebPage WebPageEmpty WebPagePreview + TranslatedText Poll PollOption Dice @@ -887,4 +889,4 @@ def start(): DESTINATION = "../../docs/source/telegram" PYROGRAM_API_DEST = "../../docs/source/api" - start() + start() \ No newline at end of file diff --git a/compiler/errors/source/400_BAD_REQUEST.tsv b/compiler/errors/source/400_BAD_REQUEST.tsv index c50f39a87..290728e1f 100644 --- a/compiler/errors/source/400_BAD_REQUEST.tsv +++ b/compiler/errors/source/400_BAD_REQUEST.tsv @@ -2,10 +2,12 @@ id message ABOUT_TOO_LONG The provided about/bio text is too long ACCESS_TOKEN_EXPIRED The bot token has expired ACCESS_TOKEN_INVALID The bot access token is invalid +ADDRESS_INVALID The specified geopoint address is invalid. ADMINS_TOO_MUCH The chat has too many administrators ADMIN_ID_INVALID The specified admin ID is invalid ADMIN_RANK_EMOJI_NOT_ALLOWED Emoji are not allowed in custom administrator titles ADMIN_RANK_INVALID The custom administrator title is invalid or too long +ADMIN_RIGHTS_EMPTY The chatAdminRights constructor passed in keyboardButtonRequestPeer.peer_type.user_admin_rights has no rights set (i.e. flags is 0). ALBUM_PHOTOS_TOO_MANY Too many photos were included in the album API_ID_INVALID The api_id/api_hash combination is invalid API_ID_PUBLISHED_FLOOD You are using an API key that is limited on the server side because it was published somewhere @@ -23,6 +25,7 @@ AUTOARCHIVE_NOT_AVAILABLE This feature is not yet enabled for your account due t BANK_CARD_NUMBER_INVALID The credit card number is invalid BANNED_RIGHTS_INVALID You provided a set of restrictions that is invalid BASE_PORT_LOC_INVALID The base port location is invalid +BIRTHDAY_INVALID The age should be less than 150 year old in Telegram BOTS_TOO_MUCH The chat has too many bots BOT_CHANNELS_NA Bots can't edit admin privileges BOT_COMMAND_DESCRIPTION_INVALID The command description was empty, too long or had invalid characters @@ -44,6 +47,7 @@ BROADCAST_ID_INVALID The channel is invalid BROADCAST_PUBLIC_VOTERS_FORBIDDEN Polls with public voters cannot be sent in channels BROADCAST_REQUIRED The request can only be used with a channel BUTTON_DATA_INVALID The button callback data is invalid or too large +BUTTON_ID_INVALID The button_id parameter is invalid BUTTON_TEXT_INVALID The specified button text is invalid BUTTON_TYPE_INVALID The type of one of the buttons you provided is invalid BUTTON_URL_INVALID The button url is invalid @@ -58,13 +62,15 @@ CHANNELS_ADMIN_PUBLIC_TOO_MUCH You are an administrator of too many public chann CHANNELS_TOO_MUCH You have joined too many channels or supergroups, leave some and try again CHANNEL_ADD_INVALID Internal error. CHANNEL_BANNED The channel is banned +CHANNEL_ID_INVALID The specified supergroup ID is invalid. CHANNEL_INVALID The channel parameter is invalid CHANNEL_PARICIPANT_MISSING The current user is not in the channel CHANNEL_PRIVATE The channel/supergroup is not accessible CHANNEL_TOO_BIG The channel too big -CHANNEL_TOO_LARGE The channel is too large +CHANNEL_TOO_LARGE "Channel is too large to be deleted; this error is issued when trying to delete channels with more than 1000 members (subject to change)." CHARGE_ALREADY_REFUNDED The charge id was already used for a refund. CHARGE_NOT_FOUND The charge id was not found. +CHATLIST_EXCLUDE_INVALID The specified `exclude_peers` are invalid. CHAT_ABOUT_NOT_MODIFIED The chat about text was not modified because you tried to edit it using the same content CHAT_ABOUT_TOO_LONG The chat about text is too long CHAT_ADMIN_REQUIRED The method requires chat admin privileges @@ -95,6 +101,7 @@ CONNECTION_SYSTEM_EMPTY The connection to the system is empty CONNECTION_SYSTEM_LANG_CODE_EMPTY The system language code is empty CONTACT_ADD_MISSING Contact to add is missing CONTACT_ID_INVALID The provided contact id is invalid +CONTACT_MISSING The specified user is not a contact. CONTACT_NAME_EMPTY The provided contact name is empty CONTACT_REQ_MISSING Missing contact request CREATE_CALL_FAILED An error occurred while creating the call @@ -109,10 +116,12 @@ DOCUMENT_INVALID The document is invalid EMAIL_HASH_EXPIRED The email hash expired and cannot be used to verify it EMAIL_INVALID The email provided is invalid EMAIL_NOT_ALLOWED This email is not allowed +EMAIL_NOT_SETUP In order to change the login email with emailVerifyPurposeLoginChange, an existing login email must already be set using emailVerifyPurposeLoginSetup. EMAIL_UNCONFIRMED Email unconfirmed EMAIL_UNCONFIRMED_X The provided email isn't confirmed, {value} is the length of the verification code that was just sent to the email EMAIL_VERIFY_EXPIRED The verification email has expired EMOJI_INVALID The specified theme emoji is valid +EMOJI_MARKUP_INVALID The specified `video_emoji_markup` was invalid. EMOJI_NOT_MODIFIED The theme wasn't changed EMOTICON_EMPTY The emoticon parameter is empty EMOTICON_INVALID The emoticon parameter is invalid @@ -129,6 +138,9 @@ ERROR_TEXT_EMPTY The provided error message is empty EXPIRE_DATE_INVALID The expiration date is invalid EXPIRE_FORBIDDEN Expire forbidden EXPORT_CARD_INVALID The provided card is invalid +EXTENDED_MEDIA_AMOUNT_INVALID The maximum amount of `star_count` should be less than the `stars_paid_post_amount_max` +EXTENDED_MEDIA_PEER_INVALID The specified chat type is invalid. +EXTENDED_MEDIA_TYPE_INVALID The specified extended media type is unsupported. EXTERNAL_URL_INVALID The external media URL is invalid FIELD_NAME_EMPTY The field with the name FIELD_NAME is missing FIELD_NAME_INVALID The field with the name FIELD_NAME is invalid @@ -157,13 +169,16 @@ FIRSTNAME_INVALID The first name is invalid FOLDER_ID_EMPTY The folder you tried to delete was already empty FOLDER_ID_INVALID The folder id is invalid FORM_ID_EXPIRED The specified id has expired. +FORUM_ENABLED You can't execute the specified action because the group is a [forum](https://core.telegram.org/api/forum), disable forum functionality to continue. FRESH_CHANGE_ADMINS_FORBIDDEN You can't change administrator settings in this chat because your session was logged-in recently FROM_MESSAGE_BOT_DISABLED Bots can't use fromMessage min constructors FROM_PEER_INVALID The from peer value is invalid GAME_BOT_INVALID You cannot send that game with the current bot +GENERAL_MODIFY_ICON_FORBIDDEN You can't modify the icon of the General topic. GEO_POINT_INVALID Invalid geo point provided GIF_CONTENT_TYPE_INVALID GIF content-type invalid GIF_ID_INVALID The provided gif/animation id is invalid +GIFT_SLUG_INVALID The specified slug is invalid. GIFT_SLUG_EXPIRED The gift slug is expired GRAPH_EXPIRED_RELOAD This graph has expired, please obtain a new graph token GRAPH_INVALID_RELOAD Invalid graph token provided, please reload the stats and provide the updated token @@ -190,7 +205,9 @@ INPUT_LAYER_INVALID The provided layer is invalid INPUT_METHOD_INVALID The method invoked is invalid in the current schema INPUT_REQUEST_TOO_LONG The input request is too long INPUT_TEXT_EMPTY The specified text is empty +INPUT_TEXT_TOO_LONG The specified text is too long. INPUT_USER_DEACTIVATED The target user has been deleted/deactivated +INVITES_TOO_MUCH The maximum number of per-folder invites specified by the `chatlist_invites_limit_default`/`chatlist_invites_limit_premium` was reached. INVITE_FORBIDDEN_WITH_JOINAS If the user has anonymously joined a group call as a channel, they can't invite other users to the group call because that would cause deanonymization, because the invite would be sent using the original user ID, not the anonymized channel ID INVITE_HASH_EMPTY The invite hash is empty INVITE_HASH_EXPIRED The chat invite link is no longer valid @@ -241,6 +258,7 @@ MULTI_MEDIA_TOO_LONG The album/media group contains too many items NEW_SALT_INVALID The new salt is invalid NEW_SETTINGS_EMPTY No password is set on the current account, and no new password was specified in `new_settings` NEW_SETTINGS_INVALID The new settings are invalid +NOGENERAL_HIDE_FORBIDDEN The hidden parameter is only valid for the General topic message_thread_id=1 NEXT_OFFSET_INVALID The next offset value is invalid OFFSET_INVALID The offset parameter is invalid OFFSET_PEER_ID_INVALID The provided offset peer is invalid @@ -301,6 +319,8 @@ POLL_QUESTION_INVALID The poll question is invalid POLL_UNSUPPORTED This layer does not support polls in the invoked method POLL_VOTE_REQUIRED Cast a vote in the poll before calling this method PREMIUM_ACCOUNT_REQUIRED The method requires a premium user account +PREMIUM_GIFTCODE_WAS_REFUNDED This gift code can't be redeemed because the giveaway organizer requested a refund +PRICING_CHAT_INVALID This chat chat doesn't support subscription link. PRIVACY_KEY_INVALID The privacy key is invalid PRIVACY_TOO_LONG Your privacy exception list has exceeded the maximum capacity PRIVACY_VALUE_INVALID The privacy value is invalid @@ -380,8 +400,15 @@ STICKER_THUMB_PNG_NOPNG A png sticker thumbnail file was expected, but something STICKER_VIDEO_BIG The specified video sticker is too big STICKER_VIDEO_NODOC You must send the video sticker as a document STICKER_VIDEO_NOWEBM A webm video file was expected, but something else was provided +STORY_ID_EMPTY You specified no story IDs. +STORY_ID_INVALID The specified story ID is invalid. +STORY_NOT_MODIFIED The new story information you passed is equal to the previous story information, thus it wasn't modified. +STORY_PERIOD_INVALID The specified story period is invalid for this account. STORIES_TOO_MUCH Too many stories in the current account +STORY_SEND_FLOOD_WEEKLY_X You've hit the weekly story limit, wait for the specified number of seconds before posting a new story. +STORY_SEND_FLOOD_MONTHLY_X You've hit the monthly story limit, wait for the specified number of seconds before posting a new story. STORY_PERIOD_INVALID The story period is invalid +SUBSCRIPTION_PERIOD_INVALID The subscription period is invalid. SWITCH_PM_TEXT_EMPTY The switch_pm.text field was empty TAKEOUT_INVALID The takeout id is invalid TAKEOUT_REQUIRED The method must be invoked inside a takeout session @@ -398,8 +425,11 @@ TMP_PASSWORD_INVALID The temporary password is invalid TOKEN_INVALID The provided token is invalid TOPIC_CLOSED The topic was closed TOPIC_DELETED The topic was deleted +TOPIC_CLOSE_SEPARATELY The close flag cannot be provided together with any of the other flags. +TOPIC_HIDE_SEPARATELY The hide flag cannot be provided together with any of the other flags. TOPIC_ID_INVALID The provided topic ID is invalid TOPIC_NOT_MODIFIED The topic was not modified +TOPIC_TITLE_EMPTY The specified topic title is empty. TO_LANG_INVALID The specified destination language is invalid TRANSCRIPTION_FAILED Telegram is having internal problems. Please try again later to transcribe the audio. TTL_DAYS_INVALID The provided TTL days is invalid @@ -440,11 +470,12 @@ USER_VOLUME_INVALID The specified user volume is invalid VIDEO_CONTENT_TYPE_INVALID The video content type is invalid (i.e.: not streamable) VIDEO_FILE_INVALID The video file is invalid VIDEO_TITLE_EMPTY The specified video title is empty -VOICE_MESSAGES_FORBIDDEN Voice messages are restricted +VOICE_MESSAGES_FORBIDDEN This user's privacy settings forbid you from sending voice messages VOLUME_LOC_NOT_FOUND The volume location can't be found WALLPAPER_FILE_INVALID The provided file cannot be used as a wallpaper WALLPAPER_INVALID The input wallpaper was not valid WALLPAPER_MIME_INVALID The wallpaper mime type is invalid +WALLPAPER_NOT_FOUND The specified wallpaper could not be found. WC_CONVERT_URL_INVALID WC convert URL invalid WEBDOCUMENT_INVALID The web document is invalid WEBDOCUMENT_MIME_INVALID The web document mime type is invalid @@ -463,5 +494,7 @@ STORIES_NEVER_CREATED You have never created any stories MEDIA_FILE_INVALID The provided media file is invalid CHANNEL_FORUM_MISSING The channel forum is missing TTL_PERIOD_INVALID The provided TTL period is invalid -BOOSTS_REQUIRED Channel required more boost to upload a story -BOOSTS_EMPTY Boosts empty \ No newline at end of file +BOOSTS_REQUIRED The specified channel must first be boosted by its users in order to perform this action +BOOSTS_EMPTY You can't modify the icon of the General topic. +BOOST_NOT_MODIFIED You're already boosting the specified channel. +BOOST_PEER_INVALID The specified `boost_peer` is invalid. diff --git a/compiler/errors/source/406_NOT_ACCEPTABLE.tsv b/compiler/errors/source/406_NOT_ACCEPTABLE.tsv index 831bc6638..f81fc8b71 100644 --- a/compiler/errors/source/406_NOT_ACCEPTABLE.tsv +++ b/compiler/errors/source/406_NOT_ACCEPTABLE.tsv @@ -14,9 +14,10 @@ PHONE_PASSWORD_FLOOD You have tried to log-in too many times PREMIUM_CURRENTLY_UNAVAILABLE Premium currently unavailable PREVIOUS_CHAT_IMPORT_ACTIVE_WAIT_XMIN Similar to a flood wait, must wait {value} minutes SEND_CODE_UNAVAILABLE Returned when all available options for this type of number were already used (e.g. flash-call, then SMS, then this error might be returned to trigger a second resend) +PREMIUM_GIFTCODE_WAS_REFUNDED This gift code can't be redeemed because the giveaway organizer requested a refund STICKERSET_INVALID The sticker set is invalid STICKERSET_OWNER_ANONYMOUS This sticker set can't be used as the group's sticker set because it was created by one of its anonymous admins UPDATE_APP_TO_LOGIN Update app to login USERPIC_PRIVACY_REQUIRED You need to disable privacy settings for your profile picture in order to make your geolocation public USERPIC_UPLOAD_REQUIRED You must have a profile picture to publish your geolocation -USER_RESTRICTED You are limited/restricted. You can't perform this action \ No newline at end of file +USER_RESTRICTED You are limited/restricted. You can't perform this action diff --git a/pyrogram/methods/invite_links/create_chat_invite_link.py b/pyrogram/methods/invite_links/create_chat_invite_link.py index 7523277b2..628e87345 100644 --- a/pyrogram/methods/invite_links/create_chat_invite_link.py +++ b/pyrogram/methods/invite_links/create_chat_invite_link.py @@ -32,7 +32,9 @@ async def create_chat_invite_link( name: str = None, expire_date: datetime = None, member_limit: int = None, - creates_join_request: bool = None + creates_join_request: bool = None, + subscription_period: int = None, + subscription_price: int = None ) -> "types.ChatInviteLink": """Create an additional invite link for a chat. @@ -64,6 +66,13 @@ async def create_chat_invite_link( True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can't be specified. + subscription_period (``int``, *optional*): + Date when the subscription will expire. + for now, only 30 days is supported (30*24*60*60). + + subscription_price (``int``, *optional*): + Subscription price (stars). + Returns: :obj:`~pyrogram.types.ChatInviteLink`: On success, the new invite link is returned. @@ -75,6 +84,9 @@ async def create_chat_invite_link( # Create a new link for up to 3 new users link = await app.create_chat_invite_link(chat_id, member_limit=3) + + # Create subcription link + link = await app.create_chat_invite_link(chat_id, subscription_period=60*24*60*60, subscription_price=1) """ r = await self.invoke( raw.functions.messages.ExportChatInvite( @@ -82,7 +94,11 @@ async def create_chat_invite_link( expire_date=utils.datetime_to_timestamp(expire_date), usage_limit=member_limit, title=name, - request_needed=creates_join_request + request_needed=creates_join_request, + subscription_pricing=raw.types.StarsSubscriptionPricing( + period=subscription_period, + amount=subscription_price + ) if subscription_period and subscription_price is not None else None ) ) diff --git a/pyrogram/methods/invite_links/export_chat_invite_link.py b/pyrogram/methods/invite_links/export_chat_invite_link.py index 86d22faa5..504d1f74f 100644 --- a/pyrogram/methods/invite_links/export_chat_invite_link.py +++ b/pyrogram/methods/invite_links/export_chat_invite_link.py @@ -22,15 +22,12 @@ import pyrogram from pyrogram import raw from pyrogram import types -from pyrogram import utils class ExportChatInviteLink: async def export_chat_invite_link( self: "pyrogram.Client", - chat_id: Union[int, str], - subscription_period: int = None, - subscription_price: int = None + chat_id: Union[int, str] ) -> "types.ChatInviteLink": """Generate a new primary invite link for a chat; any previously generated primary link is revoked. @@ -51,15 +48,8 @@ async def export_chat_invite_link( (in the format @username). You can also use chat public link in form of *t.me/* (str). - subscription_period (``int``, *optional*): - Date when the subscription will expire. - for now, only 30 days is supported (30*24*60*60). - - subscription_price (``int``, *optional*): - Subscription price (stars). - Returns: - :obj:`~pyrogram.types.ChatInviteLink`: On success, the invite link is returned. + ``str``: On success, the new invite link as string is returned. Example: .. code-block:: python @@ -70,12 +60,8 @@ async def export_chat_invite_link( r = await self.invoke( raw.functions.messages.ExportChatInvite( peer=await self.resolve_peer(chat_id), - legacy_revoke_permanent=True, - subscription_pricing=raw.types.StarsSubscriptionPricing( - period=subscription_period, - amount=subscription_price - ) + legacy_revoke_permanent=True ) ) - return types.ChatInviteLink._parse(self, r) + return r.link diff --git a/pyrogram/methods/messages/__init__.py b/pyrogram/methods/messages/__init__.py index 677e282de..b4303b7b7 100644 --- a/pyrogram/methods/messages/__init__.py +++ b/pyrogram/methods/messages/__init__.py @@ -72,7 +72,7 @@ from .stop_poll import StopPoll from .stream_media import StreamMedia from .vote_poll import VotePoll - +from .translate_text import TranslateText class Messages( DeleteMessages, @@ -129,6 +129,7 @@ class Messages( GetDiscussionReplies, GetDiscussionRepliesCount, StreamMedia, - GetCustomEmojiStickers + GetCustomEmojiStickers, + TranslateText ): pass diff --git a/pyrogram/methods/messages/translate_text.py b/pyrogram/methods/messages/translate_text.py new file mode 100644 index 000000000..edffdbea5 --- /dev/null +++ b/pyrogram/methods/messages/translate_text.py @@ -0,0 +1,104 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import List, Optional, Union + +import pyrogram +from pyrogram import enums, raw, types, utils + + +class TranslateText: + async def translate_message_text( + self: "pyrogram.Client", + to_language_code: str, + chat_id: Optional[Union[int, str]] = None, + message_ids: Optional[Union[int, List[int]]] = None, + text: Optional[str] = None, + parse_mode: Optional["enums.ParseMode"] = 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. + + Parameters: + to_language_code (``str``): + Language code of the language to which the message/text is translated. + Must be one of the supported language codes. + + chat_id (``Optional[int | str]``): + Unique identifier (int) or username (str) of the target chat. + + message_ids (``Optional[int | List[int]]``): + Identifier or list of message identifiers of the target message(s). + + text (``Optional[str]``): + Text to translate. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in message text, which can be specified instead of *parse_mode*. + + Returns: + :obj:`~pyrogram.types.TranslatedText` | List of :obj:`~pyrogram.types.TranslatedText`: In case *message_ids* was not + a list, a single result is returned, otherwise a list of results is returned. + """ + if text is not None: + message, entities = ( + await utils.parse_text_entities( + self, + text, + parse_mode, + entities + ) + ).values() + + r = await self.invoke( + raw.functions.messages.TranslateText( + to_lang=to_language_code, + text=[ + raw.types.TextWithEntities( + text=message, + entities=entities or [] + ) + ] + ) + ) + + elif chat_id is not None and message_ids is not None: + ids = [message_ids] if not isinstance(message_ids, list) else message_ids + + r = await self.invoke( + raw.functions.messages.TranslateText( + to_lang=to_language_code, + peer=await self.resolve_peer(chat_id), + id=ids + ) + ) + else: + 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 diff --git a/pyrogram/types/messages_and_media/__init__.py b/pyrogram/types/messages_and_media/__init__.py index 9cf9d3e54..79558d900 100644 --- a/pyrogram/types/messages_and_media/__init__.py +++ b/pyrogram/types/messages_and_media/__init__.py @@ -70,6 +70,7 @@ from .exported_story_link import ExportedStoryLink from .wallpaper import Wallpaper from .wallpaper_settings import WallpaperSettings +from .translated_text import TranslatedText __all__ = [ "Animation", @@ -124,5 +125,6 @@ "StoriesPrivacyRules", "ExportedStoryLink", "Wallpaper", - "WallpaperSettings" + "WallpaperSettings", + "TranslatedText" ] diff --git a/pyrogram/types/messages_and_media/message.py b/pyrogram/types/messages_and_media/message.py index 8a2ff1ea1..a104abb67 100644 --- a/pyrogram/types/messages_and_media/message.py +++ b/pyrogram/types/messages_and_media/message.py @@ -5277,3 +5277,33 @@ async def ask( reply_message.request = request return reply_message + + 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 + await client.translate_message_text( + chat_id=message.chat.id, + message_ids=message_id, + to_language_code="en" + ) + Example: + .. code-block:: python + await message.translate("en") + Parameters: + to_language_code (``str``): + Language code of the language to which the message is translated. + Must be one of "af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "zh-CN", "zh", "zh-Hans", "zh-TW", "zh-Hant", "co", "hr", "cs", "da", "nl", "en", "eo", "et", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu". + Returns: + :obj:`~pyrogram.types.TranslatedText`: The translated result is returned. + Raises: + 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 + ) \ No newline at end of file diff --git a/pyrogram/types/messages_and_media/translated_text.py b/pyrogram/types/messages_and_media/translated_text.py new file mode 100644 index 000000000..f171b4f82 --- /dev/null +++ b/pyrogram/types/messages_and_media/translated_text.py @@ -0,0 +1,61 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +from typing import List + +import pyrogram +from pyrogram import raw, types + +from ..object import Object +from .message import Str + + +class TranslatedText(Object): + """A translated text with entities. + + Parameters: + text (``str``): + Translated text. + + entities (``str``, *optional*): + Entities of the text. + """ + + 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" + ) -> "TranslatedText": + entities = [ + types.MessageEntity._parse(client, entity, {}) + for entity in translate_result.entities + ] + 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 + ) diff --git a/pyrogram/types/user_and_chats/chat.py b/pyrogram/types/user_and_chats/chat.py index 7618fe481..bf3337158 100644 --- a/pyrogram/types/user_and_chats/chat.py +++ b/pyrogram/types/user_and_chats/chat.py @@ -1071,11 +1071,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 - ): + async def export_invite_link(self): """Bound method *export_invite_link* of :obj:`~pyrogram.types.Chat`. Use as a shortcut for: @@ -1089,14 +1085,6 @@ async def export_invite_link( chat.export_invite_link() - Parameters: - subscription_period (``int``, *optional*): - Channel members only. Date when the subscription expires. - for now, only 30 days is supported (30*24*60*60). - - subscription_price (``int``, *optional*): - Channel members only. Price of the subscription in the smallest units of the currency. - Returns: ``str``: On success, the exported invite link is returned. @@ -1104,11 +1092,7 @@ async def export_invite_link( ValueError: In case the chat_id belongs to a user. """ - return await self._client.export_chat_invite_link( - self.id, - subscription_period=subscription_period, - subscription_price=subscription_price - ) + return await self._client.export_chat_invite_link(self.id) async def get_member( self,