[Tutor] IRC bot

Ulrich Holtzhausen ulrich at lavabit.com
Thu Sep 20 12:17:14 CEST 2007


I recently used the existing codebase of a very very simple IRC bot of 
which is in one of O'Reilly's books. I modified it a bit and added the 
NICK properties etc. and I was able to get it to join the server and my 
IRC channel. However I'd like to know how can I get it to print to 
screen what's happening in the channel, because it only prints that it's 
connecting to the network and that it's connected. I want it to show the 
MOTD etc. of the server.

Also, if anyone knows how, how can I set the /ctcp version reply in the 
code so that if someone requests the version it's sent? Below is the script:

<<<----------------------------------------------------------------------------------------------------------------------------------->>>
import socket
import string

HOST="irc.opera.com"
PORT=6667
NICK="pyKe"
IDENT="pyke"
REALNAME="pyKe - KeN's Python bot."
CHANNEL="#ChatterBox"
readbuffer=""

s=socket.socket( )
s.connect((HOST, PORT))
s.send("NICK %s\r\n" % NICK)
s.send("USER %s %s +iwxb :%s\r\n" % (IDENT, HOST, REALNAME))
s.send("JOIN %s\r\n" % CHANNEL)
data_received = s.recv(1024)
print data_received

while 1:
    readbuffer=readbuffer+s.recv(1024)
    temp=string.split(readbuffer, "\n")
    readbuffer=temp.pop( )

    for line in temp:
        line=string.rstrip(line)
        line=string.split(line)

        if(line[0]=="PING"):
            s.send("PONG %s\r\n" % line[1])
<<<----------------------------------------------------------------------------------------------------------------------------------->>>

Thanks in advance



More information about the Tutor mailing list