From 550604f7de4ee54715ec22f08a7fc65b19747e3f Mon Sep 17 00:00:00 2001 From: nsensfel Date: Thu, 31 Jan 2019 09:27:02 +0100 Subject: Maybe adds a last resort timeout function. --- jh-discord.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/jh-discord.py b/jh-discord.py index fc85733..9b0d059 100644 --- a/jh-discord.py +++ b/jh-discord.py @@ -2,7 +2,9 @@ import discord import asyncio import argparse import socket - +import threading +import sys +import time ################################################################################ ## MAIN ######################################################################## @@ -104,4 +106,13 @@ async def on_message(message): if (len(result) > 0): await client.send_message(message.channel, result) +def exit_if_disconnected (): + while True: + time.sleep(61) + + if ((not client.is_logged_in) or client.is_closed): + print("Timed out.") + sys.exit() + +threading.Thread(target=exit_if_disconnected).start() client.run(args.token) -- cgit v1.2.3-70-g09d2