increase delay between irc messages sent, to avoid flood
[electrum-server.git] / backends / irc / __init__.py
index b401462..5511d8f 100644 (file)
@@ -78,7 +78,7 @@ class IrcThread(threading.Thread):
             try:
                 s = socket.socket()
                 s.connect(('irc.freenode.net', 6667))
-                s.settimeout(0.1)
+                s.settimeout(0.3)
             except:
                 s.close()
                 print_log("IRC: reconnect in 10 s")
@@ -120,23 +120,25 @@ class IrcThread(threading.Thread):
                         line = line.split()
                         if line[0] == 'PING':
                             out_msg.append('PONG ' + line[1] + '\n')
-                        elif '353' in line:  # answer to /names
-                            k = line.index('353')
-                            for item in line[k+1:]:
+                        elif line[1] == '353':  # answer to /names
+                            for item in line[2:]:
                                 if item.startswith(self.prepend):
                                     out_msg.append('WHO %s\n' % item)
-                        elif '352' in line:  # answer to /who
-                            # warning: this is a horrible hack which apparently works
-                            k = line.index('352')
+                        elif line[1] == '352':  # answer to /who
                             try:
-                                ip = socket.gethostbyname(line[k+4])
+                                ip = socket.gethostbyname(line[5])
                             except:
-                                print_log("gethostbyname error", line[k+4])
+                                print_log("gethostbyname error", line[5])
                                 continue
-                            name = line[k+6]
-                            host = line[k+9]
-                            ports = line[k+10:]
+                            name = line[7]
+                            host = line[10]
+                            ports = line[11:]
                             self.peers[name] = (ip, host, ports)
+                        elif line[1] == 'KICK':
+                            try:
+                                print_log("KICK", line[3] + line[4])
+                            except:
+                                print_log("KICK", "error")
 
                     if time.time() - t > 5*60:
                         #self.processor.push_response({'method': 'server.peers', 'params': [self.get_peers()]})