From 5f0d1c435b31aa0ce38668401b6a8f905dc66852 Mon Sep 17 00:00:00 2001 From: Quentin Gibeaux Date: Tue, 6 Nov 2018 14:57:44 +0100 Subject: [PATCH] auto reconnect for handling connection problems cf #3202 --- bot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot.py b/bot.py index f0b4d44..10deff5 100755 --- a/bot.py +++ b/bot.py @@ -256,10 +256,13 @@ def main(): ready_to_read, b, c = select.select([ircsock],[],[], 1) # b&c are ignored here process_newcomers(WelcomeBot, [i for i in WelcomeBot.newcomers if i.around_for() > WelcomeBot.wait_time], ircsock,settings.channel, settings.channel_greeters) if ready_to_read: + last_read = datetime.datetime.utcnow() ircmsg = msg_handler(ircsock) # gets message from ircsock ircmsg, actor = parse_messages(ircmsg) # parses it or returns None if ircmsg is not None: # If we were able to parse it message_response(WelcomeBot, ircmsg, actor, ircsock, settings.channel, settings.channel_greeters) # Respond to the parsed message + if datetime.datetime.utcnow() - last_read > datetime.timedelta(minutes=10): + raise Exception('timeout: nothing to read on socket since 10 minutes') if __name__ == "__main__": # This line tells the interpreter to only execute main() if the program is being run, not imported. sys.exit(main())