#!/usb/bin/env python"""See also: RFC 1459"""import sysimport socketimport stringHOST = "irc.freenode.net"PORT = 6667NICK = "testboted"IDENT = "testboted"REALNAME = "blabla"CHAN = "#friendslug"DEBUG = True# This is to make sure everything works fineREAD_BUFFER = ""SOCKET = socket.socket( )SOCKET.connect((HOST, PORT))SOCKET.send("NICK %s\r\n" % NICK)SOCKET.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))SOCKET.send("JOIN :%s\r\n" % CHAN)#SOCKET.send("JOIN :%s\r\n" % "#ircrobots2")SOCKET.send("PRIVMSG %s :%s\r\n" % (CHAN, "Okay i'm ready boss"))BAD_WORDS = ['duck', 'crap']BAD_WORD_MESSAGE = "Avoid the word:"def shut_down(): """Shutdown the bot""" SOCKET.shutdown(1) sys.exit()def get_username(data): """Get the username.""" # Get the username who say hello name = data.split()[0] # Remove the unwanted data name = string.strip(name[1:]) name = name.split('!')[0] return namewhile 1: READ_BUFFER = READ_BUFFER + SOCKET.recv(1024) TEMP = string.split(READ_BUFFER, "\n") READ_BUFFER = TEMP.pop( ) for line in TEMP: line = string.rstrip(line) line_splitted = string.split(line) if DEBUG: print line if(line_splitted[0] == "PING"): SOCKET.send("PONG %s\r\n" % line[1]) # If we only say the word 'hello' (start wiht 'hello') #if(line_splitted[-1] == ":hello"): # s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Heeeellloooooo")) #s.send("heeelllloo\r\n" % line[1]) # If the word 'hello' is found if ("hello" in line): NAME = get_username(line) SOCKET.send("PRIVMSG %s :%s: %s\r\n" % (CHAN, NAME, "Heeelllooo you")) # If we only say the word 'quit' if(line_splitted[-1] == ":quit"): shut_down() if ("names" in line_splitted): SOCKET.send("NAMES :%s\r\n" % CHAN) # Join a channel if ("join" in line_splitted): SOCKET.send("JOIN :%s\r\n" % "#ircrobots2") # Tcheck if we say some bad words for item in BAD_WORDS: if item in line: NAME = get_username(line) SOCKET.send("PRIVMSG %s :%s: %s %s\r\n" % (CHAN, NAME, BAD_WORD_MESSAGE, item))