I have a working bot (thanks to abarnert) and it has one bug: it won’t join a channel. He can make it work but I can not. I realize that this may be a problem on my side, but I am connected just fine on X-Chat.
host = "irc.kbfail.net"
port = 6667
nick = "Alice"
ident = "Alice"
realname = "Alice"
channel = "#nb"
readbuffer = ""
irc = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
irc.connect ( ( host, port ) )
print irc.recv ( 4096 )
irc.send ("NICK %s\r\n" % nick)
irc.send ("USER %s %s bla :%s\r\n" % (ident, host, realname))
irc.send ("JOIN %s\r\n" % channel)
That is all up to the JOIN command. My bot is connected to the server and stops right at “:Alice MODE Alice :+x”
As I explained in your other question, you really need to log the input and output to see what’s happening. That’s the only way you—or anyone else—is going to be able to debug this.
Again, there are multiple ways to do this: Hack up your bot source to print everything it receives and sends on the socket, run a fake server with netcat, set up netcat as a proxy, run a local IRC server that’s set to log everything, use Wireshark to capture the messages on the wire… It doesn’t matter which one you choose, but you need to do one of these.
From doing this on my own local copy, I can see that you’re sending JOIN too early, and you’re getting an error back from the server:
Meanwhile, the reason your bot stops right at the MODE line is that nobody is sending anything to you after that. Fire up a client and
/MSG Alice fooand you’ll see that you’re still receiving messages just fine.So, when is the right time to send the JOIN? My guess is that you need to wait until after the /MOTD, or maybe after the automatic MODE command, or maybe just after it’s acknowledged your NICK command. But really, you shouldn’t be guessing here. The IRC protocol is very well documented, and not that complicated.
On top of that, unless you’re doing this as a learning exercise for how to write socket-based client apps, you’re wasting a lot of time; there are dozens of open source Python IRC bots and modules to help writing IRC bots so you don’t have to deal with all this low-level stuff yourself, as a quick Google search will show you.