From 3432edbb553678e3d2ac0b5945cbfb3d1e7619ed Mon Sep 17 00:00:00 2001 From: Deko Date: Sun, 31 Dec 2023 19:31:45 +0100 Subject: [PATCH] Check how recently the streamer was live before pinging again --- app/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/main.py b/app/main.py index fa7e9f1..f51d8e5 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ import os import time +from datetime import datetime from loguru import logger from requests import HTTPError @@ -10,6 +11,7 @@ from app.twitch_client import StreamInformation, TwitchClient class Main: is_live: bool = False + last_live_at = None _previous_stream: StreamInformation = None def __init__(self): @@ -36,9 +38,23 @@ class Main: if not self.is_live: logger.info("Streamer went live.") + if ( + self.last_live_at + and (datetime.now() - self.last_live_at).total_seconds() + < 300 + ): + logger.info( + "Streamer was already live once in the past 5 minutes. " + "This is probably due to a crash, not sending the Discord ping." + ) + self.last_live_at = datetime.now() + self.is_live = True + return + self.discord_client.send_information_to_discord( stream=stream, profile_image=self.profile_image ) + self.last_live_at = datetime.now() self.is_live = True else: logger.info("Streamer still live.")