IRC Bot trouble..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yawgmoth7

    #1

    IRC Bot trouble..

    I'm currently writing a IRC bot for fun...here is the code that I have
    writen so far:

    import sys
    import socket
    import string
    import time
    HOST="irc.freen ode.net"
    PORT=6667
    NICK="PapaJorgi o_"
    IDENT="Papa"
    REALNAME="Jorgi o"
    CHANNEL = "#holder"
    buffer = ""
    clientsock=sock et.socket()
    clientsock.conn ect((HOST, PORT))
    clientsock.send ("NICK %s\r\n" % NICK)
    clientsock.send ("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
    clientsock.send ("JOIN %s\r\n" % (CHANNEL))
    clientsock.send ("PRIVMSG #holder :There's a new AI in town foo.\r\n")
    while 1:
    buffer=buffer+c lientsock.recv( 1024)
    temp=string.spl it(buffer, "\n")
    print buffer
    buffer=temp.pop ()
    for line in temp:
    print "|%s|" % repr(line)
    line=string.rst rip(line)
    if "-part" in line:
    clientsock.send ("PART #holder :I am leet.\r\n")
    elif "hello" in line:
    clientsock.send ("PRIVMSG #holder :Hey...\r\n")
    elif "BlueInfern o" in line:
    clientsock.send ("PRIVMSG #holder :OH NOES! >:o\r\n")
    elif "-whois" in line:
    query = line.split()[4]
    clientsock.send ("WHOIS eff.org %s\r\n" % query)
    buffer2 = clientsock.recv (1024)
    clientsock.send ("PRIVMSG #holder :%s\r\n" % buffer2)
    elif "-nick" in line:
    nick = line.split()[4]
    clientsock.send ("NICK %s\n" % nick)
    elif "PING" in line:
    clientsock.send ("PONG %s\r\n" % line[1])

    Now...it is in a very early stage (started writing it maybe 45 minutes
    ago). But, I have a few questions regarding some of the code that is
    not working. One of the things I ham having a big trouble with is the
    -whois part. I know that I cannot assign a variable like that (Since
    socket's don't really work that way..I believe?). Basically I want to
    it run a -whois query and print it to the channel..but I can not get
    it to print it to the channel.Another problem is the 'PING' part. I
    have no clue why it doesn't respond with PONG...it should work. I am
    our of ideas >:(. Does anyone have any suggestions? Thank you for your
    time/help.
Working...