From a21664d7029f3ee9d4450f5d5f2726a9b7932a6b Mon Sep 17 00:00:00 2001 From: Ivan Filipenkov Date: Tue, 5 Dec 2023 21:25:38 +0100 Subject: [PATCH] feat: support proxy --- guide/docs/installation.md | 19 +++++++++++++++++++ poetry.lock | 35 ++++++++++++++++++++++++++++++++++- pyproject.toml | 1 + tgpy/main.py | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/guide/docs/installation.md b/guide/docs/installation.md index 4222550..1f32005 100644 --- a/guide/docs/installation.md +++ b/guide/docs/installation.md @@ -130,3 +130,22 @@ Instructions are coming. Config, session, and modules are stored in `~/.config/tgpy` directory (unless you’re using Docker.) You can change this path via `TGPY_DATA` environment variable. + +## Using proxy + +If you require proxy to connect to Telegram, do the following: + +1. Launch TGPy and provide api_id and api_hash, then quit. +2. Open `config.yml` file (see Data storage above) and add your proxy settings here: + ```yaml + core: + api_hash: ... + api_id: ... + proxy: + proxy_type: socks5 + addr: ... + port: ... + username: ... + password: ... + ``` +3. Run TGPy normally diff --git a/poetry.lock b/poetry.lock index 17a22ec..008e383 100644 --- a/poetry.lock +++ b/poetry.lock @@ -27,6 +27,18 @@ files = [ {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, ] +[[package]] +name = "async-timeout" +version = "4.0.3" +description = "Timeout context manager for asyncio programs" +category = "main" +optional = false +python-versions = ">=3.7" +files = [ + {file = "async-timeout-4.0.3.tar.gz", hash = "sha256:4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f"}, + {file = "async_timeout-4.0.3-py3-none-any.whl", hash = "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"}, +] + [[package]] name = "black" version = "22.12.0" @@ -798,6 +810,27 @@ docs = ["Jinja2 (==3.0.3)", "Sphinx (==1.8.6)"] mypy = ["mypy", "types-requests"] test = ["coverage (>=5,<6)", "mock (==1.3.0)", "pytest (>=7,<8)", "pytest-mock (>=2,<3)", "pytest-xdist (>=1,<2)", "responses (==0.13.3)"] +[[package]] +name = "python-socks" +version = "2.4.3" +description = "Core proxy (SOCKS4, SOCKS5, HTTP tunneling) functionality for Python" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "python-socks-2.4.3.tar.gz", hash = "sha256:135430ae36d582dc834c983696c5f66177aa5b587407f540985d616ef2e0c701"}, + {file = "python_socks-2.4.3-py3-none-any.whl", hash = "sha256:a57559b3f6073855761cb58b47a71bc5df8b72963d4a7a6e988b39dedd0e7ef2"}, +] + +[package.dependencies] +async-timeout = {version = ">=3.0.1", optional = true, markers = "extra == \"asyncio\""} + +[package.extras] +anyio = ["anyio (>=3.3.4,<5.0.0)"] +asyncio = ["async-timeout (>=3.0.1)"] +curio = ["curio (>=1.4)"] +trio = ["trio (>=0.16.0)"] + [[package]] name = "pywin32-ctypes" version = "0.2.2" @@ -1168,4 +1201,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "0f9d3b051b1270eb7df4e58a7e29be23c9eae8345447cb8830520217a9b4794e" +content-hash = "daf0c0c6fa9f9d45aa66873fcff68363595d57f7a919944129715fc190e05ec1" diff --git a/pyproject.toml b/pyproject.toml index 04c7a94..d440539 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ rich = "^12.5.1" appdirs = "^1.4.4" telethon-v1-24 = "^1.24.12" cryptg-anyos = "^0.4.1" +python-socks = {extras = ["asyncio"], version = "^2.4.3"} [tool.poetry.dev-dependencies] python-semantic-release = "^7.31.2" diff --git a/tgpy/main.py b/tgpy/main.py index 3d77873..283387b 100644 --- a/tgpy/main.py +++ b/tgpy/main.py @@ -60,6 +60,7 @@ def create_client(): system_version=platform.platform(), lang_code='en', system_lang_code='en-US', + proxy=config.get('core.proxy', None), ) client.parse_mode = 'html' return client