from liveMan import DouyinLiveWebFetcher, DouyinLiveWebReply
from helper import PromptQueue, LiveChatConfig
from multiprocessing import Process, Event, freeze_support
from loguru import logger


logger.add('log.log', encoding='utf-8', rotation="500MB")

def fetch_user_chat_content(ws_open_event, queue):
    fetcher = DouyinLiveWebFetcher(ws_open_event, queue)
    fetcher.start()


def reply_user_chat_content(queue):
    reply = DouyinLiveWebReply(queue)
    reply()


if __name__ == '__main__':
    freeze_support()

    LiveChatConfig().update_chat_enable_status('启动中')

    queue = PromptQueue(10)
    ws_open_event = Event()

    fetch_process = Process(target=fetch_user_chat_content, args=(ws_open_event, queue))
    reply_process = Process(target=reply_user_chat_content, args=(queue,))
    fetch_process.start()
    ws_open_event.wait()
    reply_process.start()
    fetch_process.join()
    reply_process.join()
