IRC client in python

The IRC RFC documentation is an important reference, but the most helpful first introduction I've found on communication between IRC client and server was really simple.

First, you need access to a *nix shell (e.g. ssh into your web host running Linux).

In the command line, open up a direct connection to an IRC server using the program 'nc'. Then you can type RFC commands directly, and see the response. Try typing

$ nc wright.freenode.net 6667
PASS whateveryoulike
NICK yournick
USER username 0 * :Real Name

There is output from the server amidst this, but now you've logged into and "registered" your user. Note: your nick isn't registered (ala NickServ), I'm referring to registering a user as outlined in section 3.1 of the RFC 2812 IRC Client Protocol.

You can now join a channel:

JOIN #yourtestchannel

See who's in the channel:

WHO #yourtestchannel

Send yourself a msg:

PRIVMSG yournick Message Text Here

Chat into the channel (send the channel a msg):

PRIVMSG #yourtestchannel Message Text Here

This is especially helpful if you're connected to the same server and channel with a different nick in a real IRC client. You can chat with yourself and msg one nick to the other, and see the "raw" IRC output that you'll have to parse to write your own client or bot.

For example, someone chatting in a channel looks something like this:

:SomeDude28!SomeDude28@hoststring-with_various_parts PRIVMSG #channel :Hey guys, what's up?

Using the RFC, you can play around with whatever functionality you want, and, more importantly, figure out how you'll need to parse things.

Oh, and don't forget to PONG occasionally, or when prompted with a PING, to avoid ping timeout.


If you want to reinvent the wheel, then you have to implement the RFC and do everything from scratch.

If you don't want to do that and would require some level of abstraction to ease your development (and which you should), then see Twisted.

There is also a Python IRC client library.


For most protocols a good way to start is to look for a document called RFC. There's one for many protocols and it defines - in depth - how it should behave.

You can find the one for IRC here.

Tags:

Python

Irc