auto reconnect for handling connection problems cf #3202

This commit is contained in:
Quentin Gibeaux 2018-11-06 14:57:44 +01:00 committed by root
parent e5d1d76a7d
commit 5f0d1c435b
1 changed files with 3 additions and 0 deletions

3
bot.py
View File

@ -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())