PING timeout added

This commit is contained in:
Bandie Yip Kojote 2016-10-18 19:36:35 +02:00
parent 6c30e89312
commit a915c3e8a6

View File

@ -20,7 +20,8 @@ IDENT = "PagerBot"
REALNAME = "https://github.com/TTYgap/PagerBot/" REALNAME = "https://github.com/TTYgap/PagerBot/"
# Channel which should be joined # Channel which should be joined
CHAN = "#supercoolchan" 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 # Mail address you're sending from
FROM = "ircbot@example.com" FROM = "ircbot@example.com"
@ -79,7 +80,9 @@ ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
time.sleep(2) time.sleep(2)
ircsock.send("MODE %s +B\r\n" % (NICK)) ircsock.send("MODE %s +B\r\n" % (NICK))
ircsock.send("JOIN %s\r\n" % (CHAN)) 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: while 1:
readbuffer = readbuffer + ircsock.recv(1024) readbuffer = readbuffer + ircsock.recv(1024)
@ -88,6 +91,9 @@ while 1:
pagingtext = "" pagingtext = ""
urgence = False urgence = False
if (time.time() - last_ping) > timeout:
raise Exception("PING timeout")
for line in temp: for line in temp:
line = string.rstrip(line) line = string.rstrip(line)
@ -95,6 +101,7 @@ while 1:
if(line[0] == "PING"): if(line[0] == "PING"):
ircsock.send("PONG %s\r\n" % line[1]) ircsock.send("PONG %s\r\n" % line[1])
last_ping = time.time()
if(line[1] == "PRIVMSG"): if(line[1] == "PRIVMSG"):
un = string.split(line[0], "!") un = string.split(line[0], "!")