add balance

This commit is contained in:
Yuriy Yuriev
2026-05-14 21:04:28 +07:00
parent bdf3fef7ec
commit fe9ada0558
7 changed files with 734 additions and 170 deletions
+19 -7
View File
@@ -41,9 +41,12 @@ class TwitchIRCClient:
try:
import ssl
ssl_context = ssl.create_default_context()
self._reader, self._writer = await asyncio.open_connection(
settings.IRC_SERVER, settings.IRC_PORT,
ssl=ssl_context
self._reader, self._writer = await asyncio.wait_for(
asyncio.open_connection(
settings.IRC_SERVER, settings.IRC_PORT,
ssl=ssl_context
),
timeout=15.0
)
await self._send(f"PASS {self.irc_oauth}")
@@ -173,13 +176,21 @@ class TwitchIRCClient:
start_time = datetime.now()
last_message_time = datetime.now()
await self.connect()
while (datetime.now() - start_time).seconds < duration:
# === ПРОВЕРКА АКТИВНОСТИ ===
if not await self.connect():
raise ConnectionError(f"IRC connect failed for #{self.channel}")
while duration == 0 or (datetime.now() - start_time).seconds < duration:
# === ПРОВЕРКА АКТИВНОСТИ ===
if is_active and not is_active():
logger.info("⏸️ Task paused/stopped, disconnecting...")
break
# Нет соединения — ждём перед повтором
if not self._connected:
await asyncio.sleep(5)
await self.connect()
continue
# === ПЕРЕПОДКЛЮЧЕНИЕ КАЖДЫЕ 30 СЕКУНД ===
if (datetime.now() - last_message_time).seconds > 30:
logger.info("🔄 Reconnecting (30s)...")
@@ -227,6 +238,7 @@ class TwitchIRCClient:
continue
if not line:
await asyncio.sleep(0.5)
continue
if line.startswith('PONG'):