Python IRC bot won't join

21days picture 21days · Jan 22, 2011 · Viewed 14.8k times · Source

I get the error message

:irc.evilzone.org NOTICE AUTH :* Looking up your hostname...

:irc.evilzone.org NOTICE AUTH :* Found your hostname (cached)

PING :7091A8FB

:irc.evilzone.org 451 JOIN :You have not registered

:irc.evilzone.org 451 PRIVMSG :You have not registered

server = "irc.evilzone.org" # Server 
port = 6667 #port connect through IRC standard is :(6667 or 9999)
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( server, port ) )
print irc.recv ( 4096 )
nick = 'Piebot' #bots name
chan = 'test' #channel
version= "1.0" #current version
irc.send ( 'NICK Pizebot\r\n' ) 
irc.send ( 'USER Pizebot Pibot Pibot :Python IRC\r\n' )
irc.send ( 'JOIN #test\r\n' ) # YOU MUST CHANGE THE CHANNEL HERE AND BELOW!!
irc.send ( 'PRIVMSG #test :Hello World.\r\n' )

while True:
    readbuffer= irc.recv(4096)

    temp=string.split(readbuffer, "\n")
    Check = readbuffer.split(':')
    print readbuffer

Keeping in mind that some of the commands I use need the temp= string.split(readbuffer,"\n") portion of the code.But with code like this

network = 'irc.evilzone.org'
port = 6667
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( network, port ) )
print irc.recv ( 4096 )
irc.send ( 'NICK ipbot\r\n' )
irc.send ( 'USER ipbot completely real :Jxxx\r\n' )
irc.send ( 'JOIN #test\r\n' )
irc.send ( 'PRIVMSG #test:Oh Hai.\r\n' )
while True:
   data = irc.recv ( 4096 )

I can successfully connect to the channel etc. Any idea?

Answer

Mickcy picture Mickcy · Sep 28, 2012

I noticed that you do not handle PING requests, some servers do not accept any other commands until you have replied to the PING request (hence not registered). You would want to connect, then NICK, check for a PING, then USER, check for PING again if there was none before USER.

Some servers like to send it after NICK, others after USER.

PING :7091A8FB\r\n

To respond to this PING, simply send:

PONG :7091A8FB\r\n

Between the : and '\r\n will be a random string that you need to send back with your PONG as shown above.