Browse Source

PING timeout added

master
Bandie Yip Kojote 4 years ago
parent
commit
a915c3e8a6
1 changed files with 9 additions and 2 deletions
  1. 9
    2
      PagerBot.py

+ 9
- 2
PagerBot.py View File

@@ -20,7 +20,8 @@ IDENT = "PagerBot"
20 20
 REALNAME = "https://github.com/TTYgap/PagerBot/"
21 21
 # Channel which should be joined
22 22
 CHAN = "#supercoolchan"
23
-
23
+# Ask the IRC network administrator what the ping frequency is. Take that and add +5
24
+timeout = 125
24 25
 
25 26
 # Mail address you're sending from
26 27
 FROM = "ircbot@example.com"
@@ -79,7 +80,9 @@ ircsock.send("USER %s %s no :%s\r\n" % (IDENT, HOST, REALNAME))
79 80
 time.sleep(2)
80 81
 ircsock.send("MODE %s +B\r\n" % (NICK))
81 82
 ircsock.send("JOIN %s\r\n" % (CHAN))
82
-print("OK\n")
83
+print("OK - Connected to %s:%s\n" % (HOST, PORT))
84
+
85
+last_ping = time.time()
83 86
 
84 87
 while 1:
85 88
     readbuffer = readbuffer + ircsock.recv(1024)
@@ -88,6 +91,9 @@ while 1:
88 91
 
89 92
     pagingtext = ""
90 93
     urgence = False
94
+    
95
+    if (time.time() - last_ping) > timeout:
96
+        raise Exception("PING timeout")
91 97
 
92 98
     for line in temp:
93 99
         line = string.rstrip(line)
@@ -95,6 +101,7 @@ while 1:
95 101
 
96 102
         if(line[0] == "PING"):
97 103
             ircsock.send("PONG %s\r\n" % line[1])
104
+            last_ping = time.time()
98 105
 
99 106
         if(line[1] == "PRIVMSG"):
100 107
             un = string.split(line[0], "!")

Loading…
Cancel
Save