IRC Bot trouble..


Y

yawgmoth7

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.freenode.net"
PORT=6667
NICK="PapaJorgio_"
IDENT="Papa"
REALNAME="Jorgio"
CHANNEL = "#holder"
buffer = ""
clientsock=socket.socket()
clientsock.connect((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+clientsock.recv(1024)
temp=string.split(buffer, "\n")
print buffer
buffer=temp.pop()
for line in temp:
print "|%s|" % repr(line)
line=string.rstrip(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 "BlueInferno" in line:
clientsock.send("PRIVMSG #holder :OH NOES! >:eek:\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 :mad:. Does anyone have any suggestions? Thank you for your
time/help.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top