#!/usr/bin/env python3 """Патч slidgram/gateway.py: передать SOCKS5-прокси из env SLIDGRAM_PROXY в Client при регистрации.""" from pathlib import Path p = Path("/venv/lib/python3.13/site-packages/slidgram/gateway.py") src = p.read_text() old = ''' tg_client = Client( str(user_jid.bare), phone_number=phone, api_id=registration_form.get("api_id") or config.API_ID, api_hash=registration_form.get("api_hash") or config.API_HASH, workdir=global_config.HOME_DIR, ) ''' new = ''' _proxy = None _proxy_url = __import__("os").environ.get("SLIDGRAM_PROXY", "") if _proxy_url and _proxy_url.startswith("socks5://"): _h = _proxy_url.split("://", 1)[1] _host, _, _port = _h.partition(":") _proxy = dict(scheme="socks5", hostname=_host, port=int(_port)) tg_client = Client( str(user_jid.bare), phone_number=phone, api_id=registration_form.get("api_id") or config.API_ID, api_hash=registration_form.get("api_hash") or config.API_HASH, workdir=global_config.HOME_DIR, proxy=_proxy, ) ''' assert old in src, "gateway.py: шаблон не найден" p.write_text(src.replace(old, new, 1)) print("gateway.py patched OK")