1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-24 03:54:20 +00:00
royalnet/bots.py

73 lines
3 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-18 22:12:07 +00:00
import statsupdate
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-09-18 22:12:07 +00:00
import os
2018-09-18 22:02:39 +00:00
logging.getLogger().disabled = True
2018-09-17 22:27:17 +00:00
logger = logging.getLogger(__name__)
2018-09-18 22:13:41 +00:00
os.environ["COLOREDLOGS_LOG_FORMAT"] = "%(asctime)s %(levelname)s %(name)s %(message)s"
2018-09-17 22:27:17 +00:00
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()
2018-09-19 16:28:40 +00:00
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],))
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],))
reddit = multiprocessing.Process(target=redditbot.process)
stats = multiprocessing.Process(target=statsupdate.process)
2017-10-30 12:45:38 +00:00
if __name__ == "__main__":
2018-09-18 22:02:39 +00:00
logger.info("Starting Discord Bot process...")
2017-10-30 12:45:38 +00:00
discord.start()
2018-09-18 22:02:39 +00:00
logger.info("Starting Telegram Bot process...")
2017-11-10 07:53:48 +00:00
telegram.start()
2018-09-18 22:02:39 +00:00
logger.info("Starting Reddit Bot process...")
2018-09-05 17:52:11 +00:00
reddit.start()
2018-12-18 18:34:34 +00:00
if not __debug__:
logger.info("Starting StatsUpdate process...")
stats.start()
else:
logger.warning("StatsUpdate process disabled in debug mode.")
try:
while True:
if discord.exitcode is not None:
2018-09-18 22:02:39 +00:00
logger.warning(f"Discord Bot exited with {discord.exitcode}")
del discord
2018-09-18 22:02:39 +00:00
logger.info("Restarting Discord Bot process...")
2018-09-19 16:28:40 +00:00
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],))
discord.start()
if telegram.exitcode is not None:
2018-09-18 22:02:39 +00:00
logger.warning(f"Telegram Bot exited with {telegram.exitcode}")
del telegram
2018-09-19 16:28:40 +00:00
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],))
2018-09-18 22:02:39 +00:00
logger.info("Restarting Telegram Bot process...")
2018-09-05 17:48:34 +00:00
telegram.start()
if reddit.exitcode is not None:
2018-09-18 22:02:39 +00:00
logger.warning(f"Reddit Bot exited with {reddit.exitcode}")
2018-09-05 17:48:34 +00:00
del reddit
2018-09-19 16:28:40 +00:00
reddit = multiprocessing.Process(target=redditbot.process)
2018-09-18 22:02:39 +00:00
logger.info("Restarting Reddit Bot process...")
2018-09-17 22:07:00 +00:00
reddit.start()
2018-12-18 18:34:34 +00:00
if not __debug__ and stats.exitcode is not None:
2018-09-18 22:02:39 +00:00
logger.warning(f"StatsUpdater exited with {stats.exitcode}")
2018-09-17 22:07:00 +00:00
del stats
2018-09-19 16:28:40 +00:00
stats = multiprocessing.Process(target=statsupdate.process)
2018-09-18 22:12:07 +00:00
logger.info("Restarting StatsUpdate process...")
2018-09-17 22:07:00 +00:00
stats.start()
2018-08-16 17:33:38 +00:00
time.sleep(10)
except KeyboardInterrupt:
2018-09-18 22:02:39 +00:00
logger.info("Now stopping...")
logger.info("Asking Discord process to stop...")
2018-09-19 16:24:01 +00:00
discord_telegram_pipe[1].send("stop")
2018-09-18 22:02:39 +00:00
logger.info("Waiting for Discord Bot process to stop...")
2018-09-17 22:07:00 +00:00
discord.join()
2018-09-18 22:02:39 +00:00
logger.info("Waiting for Telegram Bot process to stop...")
2018-09-17 22:07:00 +00:00
telegram.join()
2018-09-18 22:02:39 +00:00
logger.info("Waiting for Reddit Bot process to stop...")
2018-09-17 22:07:00 +00:00
reddit.join()
2018-09-18 22:12:07 +00:00
logger.info("Waiting for StatsUpdate process to stop...")
2018-09-17 22:07:00 +00:00
stats.join()