-from aptbot.bot import Bot, Message, Commands
+from aptbot import Bot, Message, Commands
import os
import importlib
import importlib.util
import analyze_auto_message
import time
import logging
+from threading import Event
from importlib import reload
reload(tools.raid)
database_manager.update_auto_messages_in_database(auto_message_modules, auto_messages)
-def start(bot: Bot, message: Message):
+def start(bot: Bot, message: Message, stop_event: Event):
i = 0
wait = 5
- while True:
+ while not stop_event.is_set():
i += wait
started = tools.smart_start_stream_time.update_start_stream_timestamp()
if started == "START":
PATH = os.path.join(TOOLS_PATH, "..")
logger.debug(f"PATH set to: {PATH}")
-streamer_login = os.path.split(STREAMER_PATH)[1]
-logger.debug(f"streamer_login set to: {streamer_login}")
+STREAMER_LOGIN = os.path.split(STREAMER_PATH)[1]
+logger.debug(f"streamer_login set to: {STREAMER_LOGIN}")
CHECK_STREAMTIME_CD = 5 * 60
def end_stream():
- logger.info("STREAM ENDED")
- print("STREAM ENDED")
+ logger.info(f"{STREAMER_LOGIN} has ended their stream")
clean_queue.clean_queue()
def start_stream():
- logger.info("STREAM STARTED")
- print("STREAM STARTED")
+ logger.info(f"{STREAMER_LOGIN} has started their stream")
clean_queue.clean_queue()
if fetched:
start_stream_ts, last_checked = fetched
- logger.debug(f"start_stream_ts set to: {start_stream_ts}")
- logger.debug(f"last_checked set to: {last_checked}")
if time.time() < last_checked + CHECK_STREAMTIME_CD:
- logger.info(f"returned cached start stream time: {start_stream_ts}")
conn.close()
return
- stream_info = ttv_api.stream.get_streams(user_logins=[streamer_login])
- logger.info(f"used twitch api to get stream info")
+ stream_info = ttv_api.stream.get_streams(user_logins=[STREAMER_LOGIN])
if not stream_info and not fetched:
- logger.info(f"streamer {streamer_login} is currently not streaming")
conn.close()
return
if not stream_info:
start_stream_ts, last_checked = fetched
- logger.debug(f"start_stream_ts set to: {start_stream_ts}")
- logger.debug(f"last_checked set to: {last_checked}")
if time.time() < last_checked + MAX_OFF_STREAM_MARGIN:
- logger.info(
- f"streamer {streamer_login} is currently not streaming, stream not considered ended yet"
- )
conn.close()
return
),
)
conn.commit()
- logger.info(f"streamer {streamer_login} has ended stream")
conn.close()
# TODO add hook, streamer ended stream
end_stream()
),
)
conn.commit()
- logger.info(
- f"inserted database with start stream {start_stream_ts}, last updated {current_time}"
- )
conn.close()
- logger.info(f"returned api start stream time: {start_stream_ts}")
- # TODO add hook, streamer started streaming
start_stream()
return "START"
),
)
conn.commit()
- logger.info(
- f"updated database with cached start stream {start_stream_ts}, last updated {current_time}"
- )
conn.close()
- logger.info(f"returned cached start stream time: {start_stream_ts}")
return