import socket import time import random HOST = "irc.freenode.net" HOME_CHANNEL = "##apbothome" NICK = "Sheldon-Cooper" PORT = 6667 SYMBOL = "#" blank = "" def ping(msg): s.send("PONG :"+ msg +"\r\n") def joinchan(channel): s.send("JOIN "+ channel +"\r\n") def output(context): s.send("PRIVMSG "+ CHANNEL +" :%s\r\n" % context) def getNick(): nick = line[1:].split("!")[0] return nick def hello(sender): output("Hello "+ sender) greetings = ['gday','g\'day','hello','hey'] #Makes the code smaller. #I'll look through this using for .. in .. later. s = socket.socket( ) s.connect((HOST, PORT)) s.send("USER "+ NICK +" "+ NICK +" "+ NICK +" :This bot was coded by webb\n") s.send("NICK "+ NICK +"\r\n") s.send("JOIN "+ HOME_CHANNEL +"\r\n") while 1: line = s.recv(2048) line = line.strip("\r\n") print line complete = line.split(":", 2) info = complete[1] if ("PING :" in line): pingcmd = line.split(":", 1) pingmsg = pingcmd[1] ping(pingmsg) elif ("JOIN" in info): print blank elif ("PART" in info): print blank else: infosplit = info.split(" ") msg = complete[2] arg = msg.split(" ") cmd = arg[0] CHANNEL = infosplit[2] if (cmd == "#join"): x = line.split(" ", 4) newchannel = x[4] joinchan(newchannel) if len(arg)>1: for each in greetings: #checks everything in greetings against cmd[0] if each == cmd[0]: hello(arg[1])