fix
This commit is contained in:
@@ -332,7 +332,7 @@ class BrowserService:
|
||||
current = new_url
|
||||
redirect = True
|
||||
task = asyncio.create_task(
|
||||
page.wait_for_load_state("load", timeout=30000)
|
||||
page.wait_for_load_state("domcontentloaded", timeout=30000)
|
||||
)
|
||||
await self._move_mouse(page, task)
|
||||
await task
|
||||
|
||||
@@ -5,6 +5,7 @@ Twitch чат через IRC over WebSocket (wss://irc-ws.chat.twitch.tv:443).
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import random
|
||||
import re
|
||||
from typing import Optional, Callable, Awaitable, List
|
||||
from datetime import datetime
|
||||
@@ -34,7 +35,13 @@ class TwitchGQLChatClient:
|
||||
):
|
||||
self.channel = channel.lower()
|
||||
self.target_username = target_username.lower()
|
||||
self.irc_username = irc_username or settings.IRC_USERNAME
|
||||
# Anonymous Twitch login (justinfanNNNNN) is shared across all clients by
|
||||
# default, so parallel monitors on the same nick get kicked by Twitch
|
||||
# (one connection per nick) — randomize it unless a real login is configured.
|
||||
if irc_username or settings.IRC_USERNAME != "justinfan12345":
|
||||
self.irc_username = irc_username or settings.IRC_USERNAME
|
||||
else:
|
||||
self.irc_username = f"justinfan{random.randint(10000, 99999)}"
|
||||
self.irc_oauth = irc_oauth or settings.IRC_OAUTH
|
||||
|
||||
self._ws: Optional[aiohttp.ClientWebSocketResponse] = None
|
||||
@@ -257,6 +264,10 @@ class TwitchGQLChatClient:
|
||||
raise
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
logger.info(
|
||||
f"🚫 Домен не разрешён: {url} (allowed_domains={allowed_domains})"
|
||||
)
|
||||
|
||||
return stats
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ IRC сервис для мониторинга Twitch чата.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import random
|
||||
import re
|
||||
import logging
|
||||
from typing import Optional, Callable, Awaitable, List
|
||||
@@ -28,7 +29,13 @@ class TwitchIRCClient:
|
||||
):
|
||||
self.channel = channel.lower()
|
||||
self.target_username = target_username.lower()
|
||||
self.irc_username = irc_username or settings.IRC_USERNAME
|
||||
# Anonymous Twitch login (justinfanNNNNN) is shared across all clients by
|
||||
# default, so parallel monitors on the same nick get kicked by Twitch
|
||||
# (one connection per nick) — randomize it unless a real login is configured.
|
||||
if irc_username or settings.IRC_USERNAME != "justinfan12345":
|
||||
self.irc_username = irc_username or settings.IRC_USERNAME
|
||||
else:
|
||||
self.irc_username = f"justinfan{random.randint(10000, 99999)}"
|
||||
self.irc_oauth = irc_oauth or settings.IRC_OAUTH
|
||||
|
||||
self._reader: Optional[asyncio.StreamReader] = None
|
||||
|
||||
@@ -11,6 +11,7 @@ import hashlib
|
||||
import json
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from aiohttp import web
|
||||
@@ -74,6 +75,21 @@ class HelketWebhookServer:
|
||||
await self._runner.cleanup()
|
||||
logger.info("Heleket webhook server stopped")
|
||||
|
||||
async def _save_lost_webhook(self, payload: dict) -> None:
|
||||
"""Сохраняет необработанный вебхук в файл и уведомляет админа."""
|
||||
lost_file = Path("data/lost_webhooks.json")
|
||||
try:
|
||||
data = []
|
||||
if lost_file.exists():
|
||||
with open(lost_file, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
data.append({**payload, "_saved_at": datetime.now().isoformat(timespec="seconds")})
|
||||
with open(lost_file, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
logger.info(f"Lost webhook saved: uuid={payload.get('uuid')}")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to save lost webhook: {e}")
|
||||
|
||||
async def _handle_health(self, request: web.Request) -> web.Response:
|
||||
return web.Response(text="ok")
|
||||
|
||||
@@ -102,9 +118,15 @@ class HelketWebhookServer:
|
||||
logger.info(f"Webhook: uuid={payment_uuid} status={status} — ignored")
|
||||
return web.Response(text="ok")
|
||||
|
||||
payment = await self._payment_storage.get(payment_uuid)
|
||||
existing = await self._payment_storage.get(payment_uuid)
|
||||
if existing and existing.get("processed"):
|
||||
logger.info(f"Webhook: payment {payment_uuid} already processed — skipping duplicate")
|
||||
return web.Response(text="ok")
|
||||
|
||||
payment = await self._payment_storage.pop(payment_uuid)
|
||||
if not payment:
|
||||
logger.warning(f"Webhook: payment {payment_uuid} not found (already processed?)")
|
||||
logger.warning(f"Webhook: payment {payment_uuid} not found in storage")
|
||||
await self._save_lost_webhook(payload)
|
||||
return web.Response(text="ok")
|
||||
|
||||
user_id = payment.get("user_id")
|
||||
@@ -147,7 +169,6 @@ class HelketWebhookServer:
|
||||
}
|
||||
logger.info(f"Webhook: user={user_id} +{rub} RUB")
|
||||
|
||||
await self._payment_storage.delete(payment_uuid)
|
||||
await self._history_storage.add(user_id, history_record)
|
||||
|
||||
if chat_id:
|
||||
|
||||
Reference in New Issue
Block a user