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

44 lines
1.7 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-01-20 14:28:04 +00:00
import time
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()
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-08-16 17:33:38 +00:00
logging.info("Starting Discord process...")
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}")
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...")
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...")
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)