1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/bots.py

50 lines
2.1 KiB
Python

import multiprocessing
import os
import telegrambot
import discordbot
import redditbot
import time
import logging
logging.getLogger().setLevel(level=logging.ERROR)
logging.getLogger(__name__).setLevel(level=logging.DEBUG)
discord_telegram_pipe = multiprocessing.Pipe()
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
reddit = multiprocessing.Process(target=redditbot.process, daemon=True)
if __name__ == "__main__":
logging.info("Starting Discord process...")
discord.start()
logging.info("Starting Telegram process...")
telegram.start()
logging.info("Starting Reddit process...")
reddit.start()
try:
while True:
if discord.exitcode is not None:
logging.warning(f"Discord Bot exited with {discord.exitcode}")
del discord
logging.info("Restarting Discord process...")
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
discord.start()
if telegram.exitcode is not None:
logging.warning(f"Telegram Bot exited with {telegram.exitcode}")
del telegram
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
logging.info("Restarting Telegram process...")
telegram.start()
if reddit.exitcode is not None:
logging.warning(f"Reddit Bot exited with {reddit.exitcode}")
del reddit
reddit = multiprocessing.Process(target=redditbot.process, daemon=True)
logging.info("Restarting Reddit process...")
telegram.start()
time.sleep(10)
except KeyboardInterrupt:
logging.info("Now stopping...")
logging.info("Asking Discord process to stop...")
discord_telegram_pipe[0].send("stop")
logging.info("Waiting for Discord process to stop...")
time.sleep(30)