Simpler keepalive response (thanks desvox), change license to BSD
parent
1f49b05e10
commit
143e5b91af
12
itte.py
12
itte.py
|
@ -1,5 +1,6 @@
|
|||
import socket
|
||||
import yaml
|
||||
from time import sleep
|
||||
from random import randint
|
||||
from sys import exit
|
||||
|
||||
|
@ -42,6 +43,7 @@ class IRC:
|
|||
self.connect(self.server, self.bot_nick)
|
||||
self.join_channels(self.channels)
|
||||
while 1:
|
||||
sleep(1)
|
||||
data = self.receive()
|
||||
self.keepalive(data)
|
||||
self.msg = self.parse(data, self.req_prefix)
|
||||
|
@ -70,11 +72,11 @@ class IRC:
|
|||
|
||||
def keepalive(self, line):
|
||||
"""Stay connected to a server by responding to server pings."""
|
||||
resp = line
|
||||
if resp != "":
|
||||
resp = line.split(" ", 1)[1]
|
||||
if ("PING " + resp) in line:
|
||||
self.send("PONG", resp)
|
||||
if line.split(" ")[0]) == "PING":
|
||||
resp = line.replace("PING", "PONG", 1)
|
||||
if self.debug:
|
||||
print("[debug][send] " + resp)
|
||||
self.sock.sendall(bytes(resp + "\r\n", "utf-8"))
|
||||
|
||||
def join_channels(self, channels):
|
||||
"""Join channels given a list of channel names."""
|
||||
|
|
Loading…
Reference in New Issue