Search code examples
pythonsocketsirc

Python: IRC Bot stopped working


I used to have a working IRC bot, which I affectionately named "shakybot", for it was very unstable in the beginning.

Now, I am recoding it. However, whenever I run it, I encounter a problem. This is the output detected from the IRC channel:

NOTICE AUTH :*** Please wait while we scan your connection for open proxies...
:Tigh.GeekShed.net NOTICE AUTH :*** Looking up your hostname...
:Tigh.GeekShed.net NOTICE AUTH :*** Found your hostname (cached)
:Tigh.GeekShed.net NOTICE AUTH :*** Checking ident...

And then it just enters the main loop. It never connects or anything, it just prints this. I am using the same code from the old version.

irc=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
irc.connect((network, port))
a=irc.recv (4096) #Setting up the Buffer
print a
irc.send('NICK ' + nick + '\r\n')
irc.send('USER shakybot shakybot bla :shakybot\r\n')
irc.send('JOIN :' + chan + '\r\n')
irc.send('PRIVMSG ' + chan + ' :Hello.\r\n')

How can I make it connect?

EDIT: After comparing the debugging messages of connecting to IRC with Mibbit and with this program, I should be getting:

Tigh.GeekShed.net *** Looking up your hostname... 
Tigh.GeekShed.net *** Checking ident... 
Tigh.GeekShed.net *** Found your hostname 
Tigh.GeekShed.net *** Received identd response 

Solution

  • What Greg says is correct. Kindly look into this code(http://code.activestate.com/recipes/299411-connect-to-an-irc-server-and-store-messages-into-a/) according to RFC1459 you need to check for PING message.

    You can also look into the some of the python IRC libraries.
    http://pypi.python.org/pypi/lalita/0.1.1
    http://pypi.python.org/pypi/irc/1.1

    Don't forget to search in pypi(http://pypi.python.org/pypi?%3Aaction=search&term=irc&submit=search)