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

51 lines
2.1 KiB
Python
Raw Normal View History

2017-10-30 12:45:38 +00:00
import multiprocessing
import os
2017-10-30 12:45:38 +00:00
import telegrambot
import discordbot
2018-09-05 17:48:34 +00:00
import redditbot
2018-01-20 14:28:04 +00:00
import time
2018-08-16 17:33:38 +00:00
import logging
logging.getLogger().setLevel(level=logging.ERROR)
logging.getLogger(__name__).setLevel(level=logging.DEBUG)
2017-10-30 12:45:38 +00:00
2017-11-15 09:48:58 +00:00
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)
2018-09-05 17:48:34 +00:00
reddit = multiprocessing.Process(target=redditbot.process, daemon=True)
2017-10-30 12:45:38 +00:00
if __name__ == "__main__":
2018-08-16 17:33:38 +00:00
logging.info("Starting Discord process...")
2017-10-30 12:45:38 +00:00
discord.start()
2018-08-16 17:33:38 +00:00
logging.info("Starting Telegram process...")
2017-11-10 07:53:48 +00:00
telegram.start()
2018-09-05 17:52:11 +00:00
logging.info("Starting Reddit process...")
reddit.start()
try:
while True:
if discord.exitcode is not None:
2018-08-16 17:33:38 +00:00
logging.warning(f"Discord Bot exited with {discord.exitcode}")
del discord
2018-09-05 17:48:34 +00:00
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:
2018-09-05 17:48:34 +00:00
logging.warning(f"Telegram Bot exited with {telegram.exitcode}")
del telegram
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
2018-09-05 17:48:34 +00:00
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()
2018-08-16 17:33:38 +00:00
time.sleep(10)
except KeyboardInterrupt:
2018-08-16 17:33:38 +00:00
logging.info("Now stopping...")
logging.info("Asking Discord process to stop...")
2018-07-31 16:31:06 +00:00
discord_telegram_pipe[0].send("stop")
2018-08-16 17:33:38 +00:00
logging.info("Waiting for Discord process to stop...")
2018-07-31 16:38:54 +00:00
time.sleep(30)