add apply proxy

This commit is contained in:
Yuriy Yuriev
2026-05-22 18:29:29 +07:00
parent 1529f27540
commit a411f2b65e
2 changed files with 21 additions and 0 deletions
+2
View File
@@ -1772,6 +1772,8 @@ class BotInterface:
await asyncio.gather(*[_check_one(p) for p in proxies], return_exceptions=True)
await self.proxy_manager.apply_check_results(results)
ok_ids = [pid for pid, ok in results.items() if ok]
fail_ids = [pid for pid, ok in results.items() if not ok]
+19
View File
@@ -417,6 +417,25 @@ class ProxyManager:
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, self._save_proxies_file)
async def apply_check_results(self, results: dict) -> None:
"""Применяет результаты проверки: помечает нерабочие и сохраняет файл.
results: {proxy.id: bool} — True=рабочий, False=нерабочий.
"""
changed = False
for proxy_id, ok in results.items():
if not ok and self._working_status.get(proxy_id, True):
self._working_status[proxy_id] = False
changed = True
logger.warning(f"Proxy {proxy_id} marked as failed (tunnel check)")
elif ok and not self._working_status.get(proxy_id, True):
self._working_status[proxy_id] = True
changed = True
logger.info(f"Proxy {proxy_id} restored as working (tunnel check)")
if changed:
loop = asyncio.get_running_loop()
await loop.run_in_executor(None, self._save_proxies_file)
def reload(self) -> int:
"""Перезагружает прокси из файла. Возвращает количество загруженных."""
self._proxies.clear()