Simpler keepalive response (thanks desvox), change license to BSD

trunk
mio 2018-10-13 15:07:59 +00:00
parent 1f49b05e10
commit 143e5b91af
2 changed files with 8 additions and 6 deletions

View File

@ -18,4 +18,4 @@ A very basic Python IRC bot script.
## License
AGPLv3
BSD

12
itte.py
View File

@ -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."""