From 20006345df72a4d35439f9f2c2cddd9207ddcaf3 Mon Sep 17 00:00:00 2001 From: klemek Date: Tue, 26 Nov 2019 13:30:18 +0100 Subject: [PATCH 1/2] rerun client on exception (and log) --- .gitignore | 3 ++- bot.py | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7c732c3..1171896 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea venv __pycache__ -.env \ No newline at end of file +.env +error_* \ No newline at end of file diff --git a/bot.py b/bot.py index e78b9f6..fee8310 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,5 @@ import os +import traceback import discord from datetime import datetime from dotenv import load_dotenv @@ -8,7 +9,7 @@ import emotes import help from utils import debug -VERSION = "1.1" +VERSION = "1.2" t0 = datetime.now() # Loading token @@ -87,5 +88,22 @@ async def on_message(message): await COMMANDS[args[0]](message, args) -# Launch client -client.run(token) +print(f"Current PID: {os.getpid()}") + +# Launch client and rerun on errors +while True: + try: + client.run(token) + break # clean kill + except Exception as e: + t = datetime.now() + print(f"Exception raised at {t:%Y-%m-%d %H:%M} : {repr(e)}") + fileName = f"error_{t:%Y-%m-%d_%H-%M-%S}.txt" + if os.path.exists(fileName): + print("Two many errors, killing") + break + with open(fileName, 'w') as f: + f.write(f"Discord Analyst v{VERSION} started at {t0:%Y-%m-%d %H:%M}\r\n" + f"Exception raised at {t:%Y-%m-%d %H:%M}\r\n" + f"\r\n" + f"{traceback.format_exc()}") From 94154fa582e16a1ea982ad6f63d2fff987274c12 Mon Sep 17 00:00:00 2001 From: klemek Date: Tue, 26 Nov 2019 13:31:20 +0100 Subject: [PATCH 2/2] release 1.2 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index dc0ccf8..79e6a57 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ python3 bot.py ## Changelog +* **v1.2**: don't quit on occasional exception * **v1.1**: * coma separator for big numbers * history loading by chunks for big channels (performance increase)