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()
|
|
|
|
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-18 22:12:07 +00:00
|
|
|
stats = multiprocessing.Process(target=statsupdate.process, daemon=True)
|
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-09-18 22:12:07 +00:00
|
|
|
logger.info("Starting StatsUpdate process...")
|
2018-09-17 22:07:00 +00:00
|
|
|
stats.start()
|
2018-04-20 17:46:33 +00:00
|
|
|
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}")
|
2018-04-20 17:46:33 +00:00
|
|
|
del discord
|
2018-09-18 22:02:39 +00:00
|
|
|
logger.info("Restarting Discord Bot process...")
|
2018-04-20 17:46:33 +00:00
|
|
|
discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True)
|
|
|
|
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}")
|
2018-04-20 17:46:33 +00:00
|
|
|
del telegram
|
|
|
|
telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_telegram_pipe[1],), daemon=True)
|
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
|
|
|
|
reddit = multiprocessing.Process(target=redditbot.process, daemon=True)
|
2018-09-18 22:02:39 +00:00
|
|
|
logger.info("Restarting Reddit Bot process...")
|
2018-09-17 22:07:00 +00:00
|
|
|
reddit.start()
|
|
|
|
if 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-18 22:12:07 +00:00
|
|
|
stats = multiprocessing.Process(target=statsupdate.process, daemon=True)
|
|
|
|
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)
|
2018-04-20 17:46:33 +00:00
|
|
|
except KeyboardInterrupt:
|
2018-09-18 22:02:39 +00:00
|
|
|
logger.info("Now stopping...")
|
|
|
|
logger.info("Asking Discord process to stop...")
|
2018-07-31 16:31:06 +00:00
|
|
|
discord_telegram_pipe[0].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()
|