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 ## License
AGPLv3 BSD

12
itte.py
View File

@ -1,5 +1,6 @@
import socket import socket
import yaml import yaml
from time import sleep
from random import randint from random import randint
from sys import exit from sys import exit
@ -42,6 +43,7 @@ class IRC:
self.connect(self.server, self.bot_nick) self.connect(self.server, self.bot_nick)
self.join_channels(self.channels) self.join_channels(self.channels)
while 1: while 1:
sleep(1)
data = self.receive() data = self.receive()
self.keepalive(data) self.keepalive(data)
self.msg = self.parse(data, self.req_prefix) self.msg = self.parse(data, self.req_prefix)
@ -70,11 +72,11 @@ class IRC:
def keepalive(self, line): def keepalive(self, line):
"""Stay connected to a server by responding to server pings.""" """Stay connected to a server by responding to server pings."""
resp = line if line.split(" ")[0]) == "PING":
if resp != "": resp = line.replace("PING", "PONG", 1)
resp = line.split(" ", 1)[1] if self.debug:
if ("PING " + resp) in line: print("[debug][send] " + resp)
self.send("PONG", resp) self.sock.sendall(bytes(resp + "\r\n", "utf-8"))
def join_channels(self, channels): def join_channels(self, channels):
"""Join channels given a list of channel names.""" """Join channels given a list of channel names."""