2017-10-30 12:45:38 +00:00
|
|
|
import multiprocessing
|
2018-04-20 17:46:33 +00:00
|
|
|
import os
|
2017-10-30 12:45:38 +00:00
|
|
|
import telegrambot
|
|
|
|
import discordbot
|
2018-01-20 14:28:04 +00:00
|
|
|
import time
|
2018-04-20 17:46:33 +00:00
|
|
|
import platform
|
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)
|
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-04-20 17:46:33 +00:00
|
|
|
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}")
|
2018-04-20 17:46:33 +00:00
|
|
|
del discord
|
2018-08-16 17:33:38 +00:00
|
|
|
logging.info("Starting Discord 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-08-16 17:33:38 +00:00
|
|
|
logging.warning(f"Telegram Bot exited with {discord.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-08-16 17:33:38 +00:00
|
|
|
logging.info("Starting Telegram process...")
|
2018-04-20 17:46:33 +00:00
|
|
|
telegram.start()
|
2018-08-16 17:33:38 +00:00
|
|
|
time.sleep(10)
|
2018-04-20 17:46:33 +00:00
|
|
|
except KeyboardInterrupt:
|
2018-08-16 17:33:38 +00:00
|
|
|
logging.info("Now stopping...")
|
2018-04-20 17:46:33 +00:00
|
|
|
if platform.system() == "Linux":
|
2018-05-25 17:58:30 +00:00
|
|
|
os.system("reset")
|
2018-08-16 17:33:38 +00:00
|
|
|
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)
|