feat: Implement a proxy pool with concurrent testing and integrate proxy management commands into the Telegram bot.

This commit is contained in:
2026-02-11 02:10:11 +08:00
parent 2ff52d5d73
commit be8dd745fb
5 changed files with 537 additions and 5 deletions

View File

@@ -53,6 +53,14 @@ except ImportError:
StripePaymentAPI = None
api_payment_with_retry = None
# 导入代理池模块
try:
import proxy_pool
PROXY_POOL_AVAILABLE = True
except ImportError:
proxy_pool = None
PROXY_POOL_AVAILABLE = False
# ================= 配置加载 =================
try:
import tomllib
@@ -2306,8 +2314,13 @@ def run_single_registration_api(progress_callback=None, step_callback=None, prox
if not ibans:
return {"success": False, "error": "没有可用的 IBAN请先通过 /iban_add 导入"}
# 使用配置的代理或传入的代理
use_proxy = proxy or API_PROXY or None
# 使用代理: 优先传入参数 > 代理池轮询 > 配置静态代理
if proxy:
use_proxy = proxy
elif PROXY_POOL_AVAILABLE and proxy_pool.get_proxy_count() > 0:
use_proxy = proxy_pool.get_next_proxy()
else:
use_proxy = API_PROXY or None
if use_proxy:
log_status("代理", f"使用代理: {use_proxy}")
@@ -2428,13 +2441,14 @@ def run_single_registration_api(progress_callback=None, step_callback=None, prox
return {"success": False, "error": f"重试 {max_user_retries} 次后仍失败: {last_error}"}
def run_single_registration_auto(progress_callback=None, step_callback=None, mode: str = None) -> dict:
def run_single_registration_auto(progress_callback=None, step_callback=None, mode: str = None, proxy: str = None) -> dict:
"""自动选择模式执行注册
Args:
progress_callback: 进度回调
step_callback: 步骤回调
mode: 强制指定模式 ("browser" / "api")None 则使用配置
proxy: 指定代理地址None 则由代理池或配置决定
Returns:
dict: 注册结果
@@ -2445,7 +2459,7 @@ def run_single_registration_auto(progress_callback=None, step_callback=None, mod
if not API_MODE_AVAILABLE:
log_status("警告", "协议模式不可用,回退到浏览器模式")
return run_single_registration(progress_callback, step_callback)
return run_single_registration_api(progress_callback, step_callback)
return run_single_registration_api(progress_callback, step_callback, proxy=proxy)
else:
return run_single_registration(progress_callback, step_callback)