This commit is contained in:
2024-08-11 21:35:26 +02:00
parent 132ee2be09
commit 72cad7345b

View File

@@ -54,7 +54,7 @@ class TwitchService:
AuthScope.CHAT_EDIT, AuthScope.CHAT_EDIT,
] ]
ONLINE_NOTIFICATION_DELAY = 5 * 60 ONLINE_NOTIFICATION_DELAY = 10 * 60
def __init__(self, twitch: Twitch): def __init__(self, twitch: Twitch):
self.twitch = twitch self.twitch = twitch
@@ -120,10 +120,10 @@ class TwitchService:
await self.notify_change_category() await self.notify_change_category()
async def on_stream_online(self, event: StreamOnlineEvent): async def _on_stream_online(self):
current_stream = await self.get_current_stream() current_stream = await self.get_current_stream()
if current_stream is None: if current_stream is None:
raise RuntimeError("Stream not found") return
state = State( state = State(
title=current_stream.title, title=current_stream.title,
@@ -137,9 +137,13 @@ class TwitchService:
await self.notify_online() await self.notify_online()
if (datetime.now() - self.state.last_live_at).seconds >= self.ONLINE_NOTIFICATION_DELAY: if (datetime.now() - self.state.last_live_at).seconds >= self.ONLINE_NOTIFICATION_DELAY:
self.state = state
await self.notify_online() await self.notify_online()
self.state = state
async def on_stream_online(self, event: StreamOnlineEvent):
await self._on_stream_online()
async def on_stream_offline(self, event: StreamOfflineEvent): async def on_stream_offline(self, event: StreamOfflineEvent):
if self.state: if self.state:
self.state.is_live = False self.state.is_live = False
@@ -176,7 +180,8 @@ class TwitchService:
logger.info("Twitch service started") logger.info("Twitch service started")
while True: while True:
await sleep(1) await sleep(5 * 60)
await self._on_stream_online()
finally: finally:
await eventsub.stop() await eventsub.stop()
await self.twitch.close() await self.twitch.close()