mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
Pyrofork: Add alt_port parameter to Client
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
5ba8cc48fc
commit
9e82bd0b57
5 changed files with 38 additions and 26 deletions
|
|
@ -1,20 +1,21 @@
|
||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
#
|
#
|
||||||
# This file is part of Pyrogram.
|
# This file is part of Pyrofork.
|
||||||
#
|
#
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
# Pyrofork is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
# 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
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# Pyrogram is distributed in the hope that it will be useful,
|
# Pyrofork is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU Lesser General Public License for more details.
|
# GNU Lesser General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import functools
|
import functools
|
||||||
|
|
@ -96,6 +97,10 @@ class Client(Methods):
|
||||||
Pass True to connect to Telegram using IPv6.
|
Pass True to connect to Telegram using IPv6.
|
||||||
Defaults to False (IPv4).
|
Defaults to False (IPv4).
|
||||||
|
|
||||||
|
alt_port (``bool``, *optional*):
|
||||||
|
Pass True to connect to Telegram using alternative port (5222).
|
||||||
|
Defaults to False (443).
|
||||||
|
|
||||||
proxy (``dict``, *optional*):
|
proxy (``dict``, *optional*):
|
||||||
The Proxy settings as dict.
|
The Proxy settings as dict.
|
||||||
E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*.
|
E.g.: *dict(scheme="socks5", hostname="11.22.33.44", port=1234, username="user", password="pass")*.
|
||||||
|
|
@ -209,6 +214,7 @@ class Client(Methods):
|
||||||
system_version: str = SYSTEM_VERSION,
|
system_version: str = SYSTEM_VERSION,
|
||||||
lang_code: str = LANG_CODE,
|
lang_code: str = LANG_CODE,
|
||||||
ipv6: bool = False,
|
ipv6: bool = False,
|
||||||
|
alt_port: bool = False,
|
||||||
proxy: dict = None,
|
proxy: dict = None,
|
||||||
test_mode: bool = False,
|
test_mode: bool = False,
|
||||||
bot_token: str = None,
|
bot_token: str = None,
|
||||||
|
|
@ -237,6 +243,7 @@ class Client(Methods):
|
||||||
self.system_version = system_version
|
self.system_version = system_version
|
||||||
self.lang_code = lang_code.lower()
|
self.lang_code = lang_code.lower()
|
||||||
self.ipv6 = ipv6
|
self.ipv6 = ipv6
|
||||||
|
self.alt_port = alt_port
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
self.test_mode = test_mode
|
self.test_mode = test_mode
|
||||||
self.bot_token = bot_token
|
self.bot_token = bot_token
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
#
|
#
|
||||||
# This file is part of Pyrogram.
|
# This file is part of Pyrofork.
|
||||||
#
|
#
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
# Pyrofork is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
# 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
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# Pyrogram is distributed in the hope that it will be useful,
|
# Pyrofork is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU Lesser General Public License for more details.
|
# GNU Lesser General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -29,14 +30,15 @@ log = logging.getLogger(__name__)
|
||||||
class Connection:
|
class Connection:
|
||||||
MAX_CONNECTION_ATTEMPTS = 3
|
MAX_CONNECTION_ATTEMPTS = 3
|
||||||
|
|
||||||
def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, proxy: dict, media: bool = False):
|
def __init__(self, dc_id: int, test_mode: bool, ipv6: bool, alt_port: bool, proxy: dict, media: bool = False):
|
||||||
self.dc_id = dc_id
|
self.dc_id = dc_id
|
||||||
self.test_mode = test_mode
|
self.test_mode = test_mode
|
||||||
self.ipv6 = ipv6
|
self.ipv6 = ipv6
|
||||||
|
self.alt_port = alt_port
|
||||||
self.proxy = proxy
|
self.proxy = proxy
|
||||||
self.media = media
|
self.media = media
|
||||||
|
|
||||||
self.address = DataCenter(dc_id, test_mode, ipv6, media)
|
self.address = DataCenter(dc_id, test_mode, ipv6, alt_port, media)
|
||||||
self.protocol: TCP = None
|
self.protocol: TCP = None
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
#
|
#
|
||||||
# This file is part of Pyrogram.
|
# This file is part of Pyrofork.
|
||||||
#
|
#
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
# Pyrofork is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
# 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
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# Pyrogram is distributed in the hope that it will be useful,
|
# Pyrofork is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU Lesser General Public License for more details.
|
# GNU Lesser General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
|
@ -41,6 +42,7 @@ class Auth:
|
||||||
self.dc_id = dc_id
|
self.dc_id = dc_id
|
||||||
self.test_mode = test_mode
|
self.test_mode = test_mode
|
||||||
self.ipv6 = client.ipv6
|
self.ipv6 = client.ipv6
|
||||||
|
self.alt_port = client.alt_port
|
||||||
self.proxy = client.proxy
|
self.proxy = client.proxy
|
||||||
|
|
||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
@ -76,7 +78,7 @@ class Auth:
|
||||||
# The server may close the connection at any time, causing the auth key creation to fail.
|
# The server may close the connection at any time, causing the auth key creation to fail.
|
||||||
# If that happens, just try again up to MAX_RETRIES times.
|
# If that happens, just try again up to MAX_RETRIES times.
|
||||||
while True:
|
while True:
|
||||||
self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy)
|
self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.alt_port, self.proxy)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log.info("Start creating a new auth key on DC%s", self.dc_id)
|
log.info("Start creating a new auth key on DC%s", self.dc_id)
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||||
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
|
||||||
|
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
|
||||||
#
|
#
|
||||||
# This file is part of Pyrogram.
|
# This file is part of Pyrofork.
|
||||||
#
|
#
|
||||||
# Pyrogram is free software: you can redistribute it and/or modify
|
# Pyrofork is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Lesser General Public License as published
|
# 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
|
# by the Free Software Foundation, either version 3 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# Pyrogram is distributed in the hope that it will be useful,
|
# Pyrofork is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU Lesser General Public License for more details.
|
# GNU Lesser General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
|
||||||
|
|
@ -60,7 +61,7 @@ class DataCenter:
|
||||||
4: "2001:067c:04e8:f004:0000:0000:0000:000b"
|
4: "2001:067c:04e8:f004:0000:0000:0000:000b"
|
||||||
}
|
}
|
||||||
|
|
||||||
def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, media: bool) -> Tuple[str, int]:
|
def __new__(cls, dc_id: int, test_mode: bool, ipv6: bool, alt_port: bool, media: bool) -> Tuple[str, int]:
|
||||||
if test_mode:
|
if test_mode:
|
||||||
if ipv6:
|
if ipv6:
|
||||||
ip = cls.TEST_IPV6[dc_id]
|
ip = cls.TEST_IPV6[dc_id]
|
||||||
|
|
@ -79,5 +80,4 @@ class DataCenter:
|
||||||
ip = cls.PROD_MEDIA.get(dc_id, cls.PROD[dc_id])
|
ip = cls.PROD_MEDIA.get(dc_id, cls.PROD[dc_id])
|
||||||
else:
|
else:
|
||||||
ip = cls.PROD[dc_id]
|
ip = cls.PROD[dc_id]
|
||||||
|
return ip, 5222 if alt_port else 443
|
||||||
return ip, 443
|
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ class Session:
|
||||||
self.dc_id,
|
self.dc_id,
|
||||||
self.test_mode,
|
self.test_mode,
|
||||||
self.client.ipv6,
|
self.client.ipv6,
|
||||||
|
self.client.alt_port,
|
||||||
self.client.proxy,
|
self.client.proxy,
|
||||||
self.is_media
|
self.is_media
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue