From 74fa9d187a6a126b6df1f269168ebc336b8895a4 Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Thu, 21 Apr 2016 22:55:41 +0100 Subject: [PATCH] Added exception handling and loop that stops Maki from dying on server errors, v0.12.2 --- bot.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 06aed50..184e8e6 100644 --- a/bot.py +++ b/bot.py @@ -27,7 +27,7 @@ from secret import email,pwd name = "Maki" # bot version -version = "v0.12.1" +version = "v0.12.2" # text shown by .help command helptext = """I am a bot written in Python by MrDetonia @@ -88,6 +88,9 @@ if os.path.isfile('tells.json'): # this instance of the Discord client client = discord.Client() +# are we running? +run = True + # logging setup logger = logging.getLogger('discord') logger.setLevel(logging.DEBUG) @@ -206,6 +209,7 @@ def on_message(message): if message.author.id in admins: # exit discord and kill bot print('INFO: Accepting .die from ' + message.author.name) + run = False yield from client.send_message(message.channel, 'But will I dream? ;_;') yield from client.logout() else: @@ -345,4 +349,15 @@ def on_message(message): # Run the client -client.run(email, pwd) +while run: + try: + print('INFO: starting client') + client.run(email, pwd) + except: + print('ERROR: caught some exception') + continue + else: + break + +# finish execution +exit(0)