Programming a Simple Irc (Internet-Relay-Chat) Client

Programming a simple IRC (Internet-Relay-Chat) Client

An earlier post mentioned RFC1459. While it is a very good introduction to IRC, it has actually been superseded by RFCs 2810-2813. Here is a more complete list of documentation you need to program anything IRC-related:

  • RFC1459 (original RFC; superseded, but still useful)
  • RFC2810 (IRC architecture)
  • RFC2811 (IRC channel management)
  • RFC2812 (IRC client protocol)
  • RFC2813 (IRC server protocol)
  • CTCP specification
  • DCC specification
  • Updated CTCP specification (not all clients support this)
  • ISupport (response code 005) draft (almost all servers support this nowadays)
  • Client capabilities (CAP command) draft (supported by some servers/clients)
  • IRCv3 standards and proposals (the future features of IRC, some of which are already widely supported)

Internet Relay Chat rfc implementation

In the first sense no. Messages are not broadcast, so the user will not receive their own message back.

When sending a message you provide the destination. Whether that's a user or a channel. So PRIVMSG #channel :hello world will target that message to #channel. Other users in that room will receive the following:

:juco!~juco@hostname.com PRIVMSG #example :Hello world

This is explained in more details in 4.4.1 Private messages.

Python IRC client: write from scratch or write plugin for existing framework?

I vote for a completely new plugin for Supybot. Learn more ;)

If you won't do so much, try python irclib. It's a (still maintained) python lib for IRC.

Twisted may also be ok, but it's a little but too much...

Internet chat service like IRC but with message history

You are looking for an IRC bouncer service. Some services also log anything that happens when you are not online through the bouncer.

How to programatically send messages to IRC channel

You basically need to:

  1. Connect to the server.
  2. Join the channel.
  3. Send the message to the channel.


Connecting

You need to open a connection to the IRC server. It's usually done with the fsockopen() function.

The server expects two commands, NICK and USER. Note that the sever expects \r\n as a line-ending (if you don't send it, the server won't accept your commands).

After those two commands are sent, the server will send you a ping.

:irc.servername.com PING :RANDOM-STRING

You must reply it with PONG :RANDOM-STRING (Same string). The server will periodically send those if you are not active. If you fail to reply, the server will assume you died, and close the connection.

Joining the channel

After connection phase is over (You can tell it because you'll get a 001 command from the server when you do), you join the channel. Send the following command:

JOIN #channel-name

The server will join you to the channel, send you the TOPIC and the NAMES list. Once that's over, you've joined the channel.

Sending the message

If all of the above went correctly, all you need is

PRIVMSG #channel-name :YOUR MESSAGE HERE

Anything after the colon is the message.


Good luck! :)



Related Topics



Leave a reply



Submit