Skip to content

Commit

Permalink
Merge pull request #2 from Klemek/dev
Browse files Browse the repository at this point in the history
release 1.2
  • Loading branch information
Klemek authored Nov 26, 2019
2 parents 0fc4227 + 94154fa commit c895484
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
venv
__pycache__
.env
.env
error_*
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 21 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import traceback
import discord
from datetime import datetime
from dotenv import load_dotenv
Expand All @@ -8,7 +9,7 @@
import help
from utils import debug

VERSION = "1.1"
VERSION = "1.2"
t0 = datetime.now()

# Loading token
Expand Down Expand Up @@ -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()}")

0 comments on commit c895484

Please sign in to comment.