From 05f342bf89a1c0917280a01d51519cb880b97e2f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 15 Nov 2017 10:48:58 +0100 Subject: [PATCH] useful commit message here --- bots.py | 12 ++++++++---- discordbot.py | 12 ++++-------- telegrambot.py | 2 -- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/bots.py b/bots.py index 45f112bb..e07276b5 100644 --- a/bots.py +++ b/bots.py @@ -2,11 +2,15 @@ import multiprocessing import telegrambot import discordbot -discord_users_pipe = multiprocessing.Pipe() - -discord = multiprocessing.Process(target=discordbot.process, args=(discord_users_pipe[0],)) -telegram = multiprocessing.Process(target=telegrambot.process, args=(discord_users_pipe[1],)) +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) if __name__ == "__main__": discord.start() telegram.start() + while True: + if discord.exitcode is not None: + print("Restarting Discord Bot...") + discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True) + discord.start() diff --git a/discordbot.py b/discordbot.py index 6d250442..1cd84b77 100644 --- a/discordbot.py +++ b/discordbot.py @@ -7,6 +7,7 @@ import sys import db import errors import youtube_dl +import os # Init the event loop import asyncio @@ -55,12 +56,6 @@ class Video: self.enqueued = enqueued self.channel = channel return self - - def add_to_db(self, started): - db.CVMusic.create_and_add(url=self.info["webpage_url"], - user=self.user, - enqueued=self.enqueued, - started=started) def create_embed(self): embed = discord.Embed(type="rich", @@ -115,7 +110,7 @@ async def on_error(event, *args, **kwargs): type, exception, traceback = sys.exc_info() try: await client.send_message(client.get_channel("368447084518572034"), f"☢️ ERRORE CRITICO NELL'EVENTO `{event}`\n" - f"Il bot si è chiuso per prevenire altri errori.\n\n" + f"Il bot si è chiuso e si dovrebbe riavviare entro qualche minuto.\n\n" f"Dettagli dell'errore:\n" f"```python\n" f"{repr(exception)}\n" @@ -126,7 +121,8 @@ async def on_error(event, *args, **kwargs): except Exception as e: print("ERRORE CRITICO PIU' CRITICO:\n" + repr(e) + "\n" + repr(sys.exc_info())) loop.stop() - sys.exit(1) + os._exit(1) + pass @client.event diff --git a/telegrambot.py b/telegrambot.py index 67fb6d54..96eb8ac3 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -10,8 +10,6 @@ from discord import Status as DiscordStatus # Init the config reader import configparser - - = u.idle() config = configparser.ConfigParser() config.read("config.ini")