From a915c3e8a6e6c1f005d70b62c81ea7cbf28cbc2c Mon Sep 17 00:00:00 2001 From: Bandie Yip Kojote Date: Tue, 18 Oct 2016 19:36:35 +0200 Subject: [PATCH] PING timeout added --- PagerBot.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/PagerBot.py b/PagerBot.py index b2d5cc7..a3b320f 100644 --- a/PagerBot.py +++ b/PagerBot.py @@ -20,7 +20,8 @@ IDENT = "PagerBot" REALNAME = "https://github.com/TTYgap/PagerBot/" # Channel which should be joined CHAN = "#supercoolchan" - +# Ask the IRC network administrator what the ping frequency is. Take that and add +5 +timeout = 125 # Mail address you're sending from FROM = "ircbot@example.com" @@ -79,7 +80,9 @@ ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME)) time.sleep(2) ircsock.send("MODE %s +B\r\n" % (NICK)) ircsock.send("JOIN %s\r\n" % (CHAN)) -print("OK\n") +print("OK - Connected to %s:%s\n" % (HOST, PORT)) + +last_ping = time.time() while 1: readbuffer = readbuffer + ircsock.recv(1024) @@ -88,6 +91,9 @@ while 1: pagingtext = "" urgence = False + + if (time.time() - last_ping) > timeout: + raise Exception("PING timeout") for line in temp: line = string.rstrip(line) @@ -95,6 +101,7 @@ while 1: if(line[0] == "PING"): ircsock.send("PONG %s\r\n" % line[1]) + last_ping = time.time() if(line[1] == "PRIVMSG"): un = string.split(line[0], "!")