diff --git a/docs/source/start/Usage.rst b/docs/source/start/Usage.rst index 6c560f90..6eac5cd1 100644 --- a/docs/source/start/Usage.rst +++ b/docs/source/start/Usage.rst @@ -33,7 +33,7 @@ Examples (more on `GitHub ` and :mod:`types ` exposed by the ``pyrogram.api`` package and call any Telegram API method you wish using the :meth:`send() ` method provided by the Client class. diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 78147a81..b03e73c6 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -90,6 +90,10 @@ class Client(Methods, BaseClient): Code of the language used on the client, in ISO 639-1 standard. Defaults to "en". This is an alternative way to set it if you don't want to use the *config.ini* file. + ipv6 (``bool``, *optional*): + Pass True to connect to Telegram using IPv6. + Defaults to False (IPv4). + proxy (``dict``, *optional*): Your SOCKS5 Proxy settings as dict, e.g.: *dict(hostname="11.22.33.44", port=1080, username="user", password="pass")*. diff --git a/pyrogram/client/methods/messages/edit_message_media.py b/pyrogram/client/methods/messages/edit_message_media.py index ae468813..7056aca2 100644 --- a/pyrogram/client/methods/messages/edit_message_media.py +++ b/pyrogram/client/methods/messages/edit_message_media.py @@ -36,6 +36,28 @@ class EditMessageMedia(BaseClient): message_id: int, media, reply_markup=None): + """Use this method to edit audio, document, photo, or video messages. + + If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, + message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. + Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent + by the bot, the edited Message is returned, otherwise True is returned. + + Args: + chat_id (``int`` | ``str``): + Unique identifier (int) or username (str) of the target chat. + For your personal cloud (Saved Messages) you can simply use "me" or "self". + For a contact that exists in your Telegram address book you can use his phone number (str). + + message_id (``int``): + Message identifier in the chat specified in chat_id. + + media (:obj:`InputMediaAnimation` | :obj:`InputMediaAudio` | :obj:`InputMediaDocument` | :obj:`InputMediaPhoto` | :obj:`InputMediaVideo`) + One of the InputMedia objects describing an animation, audio, document, photo or video. + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + """ style = self.html if media.parse_mode.lower() == "html" else self.markdown caption = media.caption diff --git a/pyrogram/connection/transport/tcp/tcp.py b/pyrogram/connection/transport/tcp/tcp.py index 91f3dd45..55e9fea6 100644 --- a/pyrogram/connection/transport/tcp/tcp.py +++ b/pyrogram/connection/transport/tcp/tcp.py @@ -19,6 +19,7 @@ import asyncio import logging import socket +import ipaddress try: import socks @@ -37,31 +38,43 @@ class TCP: TIMEOUT = 10 def __init__(self, ipv6: bool, proxy: dict): - self.proxy = proxy - - self.lock = asyncio.Lock() - - self.socket = socks.socksocket(family=socket.AF_INET6 if ipv6 else socket.AF_INET) - - self.socket.settimeout(TCP.TIMEOUT) + self.socket = None self.reader = None # type: asyncio.StreamReader self.writer = None # type: asyncio.StreamWriter - self.proxy_enabled = proxy.get("enabled", False) - if proxy and self.proxy_enabled: + self.lock = asyncio.Lock() + + if proxy.get("enabled", False): + hostname = proxy.get("hostname", None) + port = proxy.get("port", None) + + try: + ip_address = ipaddress.ip_address(hostname) + except ValueError: + self.socket = socks.socksocket(socket.AF_INET) + else: + if isinstance(ip_address, ipaddress.IPv6Address): + self.socket = socks.socksocket(socket.AF_INET6) + else: + self.socket = socks.socksocket(socket.AF_INET) + self.socket.set_proxy( proxy_type=socks.SOCKS5, - addr=proxy.get("hostname", None), - port=proxy.get("port", None), + addr=hostname, + port=port, username=proxy.get("username", None), password=proxy.get("password", None) ) - log.info("Using proxy {}:{}".format( - proxy.get("hostname", None), - proxy.get("port", None) - )) + log.info("Using proxy {}:{}".format(hostname, port)) + else: + super().__init__( + socket.AF_INET6 if ipv6 + else socket.AF_INET + ) + + self.socket.settimeout(TCP.TIMEOUT) async def connect(self, address: tuple): self.socket.connect(address) diff --git a/setup.py b/setup.py index 10789e98..78d01fa8 100644 --- a/setup.py +++ b/setup.py @@ -130,6 +130,7 @@ class Generate(Command): if len(argv) > 1 and argv[1] in ["bdist_wheel", "install"]: error_compiler.start() api_compiler.start() + docs_compiler.start() setup( name="Pyrogram",