mirror of
https://github.com/kurbezz/discord-bot.git
synced 2026-03-03 15:40:48 +01:00
Fix
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Literal
|
|
||||||
|
|
||||||
from httpx import AsyncClient
|
from httpx import AsyncClient
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from asyncio import sleep, gather, get_running_loop
|
from asyncio import sleep, gather
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
import logging
|
import logging
|
||||||
from typing import NoReturn, Literal
|
from typing import NoReturn, Literal
|
||||||
@@ -11,7 +11,7 @@ from twitchAPI.oauth import validate_token
|
|||||||
|
|
||||||
from core.config import config
|
from core.config import config
|
||||||
from repositories.streamers import StreamerConfigRepository, StreamerConfig
|
from repositories.streamers import StreamerConfigRepository, StreamerConfig
|
||||||
from modules.stream_notifications.tasks import on_stream_state_change
|
from modules.stream_notifications.tasks import on_stream_state_change, check_streams_states
|
||||||
|
|
||||||
from .authorize import authorize
|
from .authorize import authorize
|
||||||
from ..state import State
|
from ..state import State
|
||||||
@@ -26,8 +26,16 @@ class TwitchService:
|
|||||||
def __init__(self, twitch: Twitch):
|
def __init__(self, twitch: Twitch):
|
||||||
self.twitch = twitch
|
self.twitch = twitch
|
||||||
|
|
||||||
|
self.failed = False
|
||||||
|
|
||||||
async def on_channel_update(self, event: ChannelUpdateEvent):
|
async def on_channel_update(self, event: ChannelUpdateEvent):
|
||||||
stream = await first(self.twitch.get_streams(user_id=[event.event.broadcaster_user_id]))
|
try:
|
||||||
|
stream = await first(self.twitch.get_streams(user_id=[event.event.broadcaster_user_id]))
|
||||||
|
except RuntimeError as e:
|
||||||
|
await check_streams_states.kiq()
|
||||||
|
self.failed = True
|
||||||
|
raise e
|
||||||
|
|
||||||
if stream is None:
|
if stream is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -93,12 +101,13 @@ class TwitchService:
|
|||||||
async def _check_token(self):
|
async def _check_token(self):
|
||||||
assert self.twitch._user_auth_token is not None
|
assert self.twitch._user_auth_token is not None
|
||||||
|
|
||||||
while True:
|
while not self.failed:
|
||||||
for _ in range(60):
|
for _ in range(60):
|
||||||
loop = get_running_loop()
|
if self.failed:
|
||||||
if loop.is_closed():
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
await sleep(1)
|
||||||
|
|
||||||
logger.info("Check token...")
|
logger.info("Check token...")
|
||||||
val_result = await validate_token(
|
val_result = await validate_token(
|
||||||
self.twitch._user_auth_token,
|
self.twitch._user_auth_token,
|
||||||
|
|||||||
Reference in New Issue
Block a user