1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00
royalnet/bots.py

68 lines
2.9 KiB
Python
Raw Normal View History

2017-10-30 12:45:38 +00:00
import multiprocessing
import telegrambot
import discordbot
2018-09-05 17:48:34 +00:00
import redditbot
2018-09-17 22:07:00 +00:00
import statsupdater
2018-01-20 14:28:04 +00:00
import time
2018-08-16 17:33:38 +00:00
import logging
2018-09-17 22:26:01 +00:00
import coloredlogs
2018-08-16 17:33:38 +00:00
2018-09-17 22:44:39 +00:00
logging.lastResort = None
2018-09-17 22:27:17 +00:00
logger = logging.getLogger(__name__)
coloredlogs.install(level="DEBUG", logger=logger)
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)
2018-09-17 22:07:00 +00:00
stats = multiprocessing.Process(target=statsupdater.process, daemon=True)
2017-10-30 12:45:38 +00:00
if __name__ == "__main__":
2018-09-17 22:07:00 +00:00
logging.info("Starting Discord Bot process...")
2017-10-30 12:45:38 +00:00
discord.start()
2018-09-17 22:07:00 +00:00
logging.info("Starting Telegram Bot process...")
2017-11-10 07:53:48 +00:00
telegram.start()
2018-09-17 22:07:00 +00:00
logging.info("Starting Reddit Bot process...")
2018-09-05 17:52:11 +00:00
reddit.start()
2018-09-17 22:07:00 +00:00
logging.info("Starting StatsUpdater process...")
stats.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-17 22:07:00 +00:00
logging.info("Restarting Discord Bot 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-17 22:07:00 +00:00
logging.info("Restarting Telegram Bot process...")
2018-09-05 17:48:34 +00:00
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)
2018-09-17 22:07:00 +00:00
logging.info("Restarting Reddit Bot process...")
reddit.start()
if stats.exitcode is not None:
logging.warning(f"StatsUpdater exited with {stats.exitcode}")
del stats
stats = multiprocessing.Process(target=statsupdater.process, daemon=True)
logging.info("Restarting StatsUpdater process...")
stats.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-09-17 22:07:00 +00:00
logging.info("Waiting for Discord Bot process to stop...")
discord.join()
logging.info("Waiting for Telegram Bot process to stop...")
telegram.join()
logging.info("Waiting for Reddit Bot process to stop...")
reddit.join()
logging.info("Waiting for StatsUpdater process to stop...")
stats.join()