Writing IRC bots using ii

I recently read about ii, a file-system based IRC client, over at IRC-Junkie which really sparked my interest.  ii provides a clean interface of FIFOs organized under a directory structure for users to communicate with an IRC network.  After playing with ii a bit at the command-line, I started to wonder about the potential for writing bots using ii as the back-end.  ii’s website provides a few examples of simple bots written in bash and perl, demonstrating how simple writing a bot with ii can be. I decided to give it a go with python and wrote a quick proof of concept script.  I was blown away with the ease of development.  From python’s (or your language of choice) perspective, IRC is simply reading from and writing to a set of files and tasks like  connecting, identifying and PONGing are handled by ii, so the focus can be on writing the bot itself.

Ease of development isn’t the only reason to use ii as a back-end. Since the bot and the connection are separate processes, a crash in one doesn’t necessarily halt the other. If your bot errors out and dies, the connection stays open and the user stays in all IRC channels ii was connected to.  You can then restart the bot without the annoying reconnects. This model also allows the bot to be updated seamlessly.  On the other end of the spectrum, should ii encounter a network issue and lose the connection, the bot can stay running and simply wait for ii to be restarted.  This allows the bot to carry over state information even when using an unreliable connection.  Finally, having file-based FIFOs as the input/output means that you can both read messages sent to the bot as well as echo messages out as the bot or have multiple bots operating on the same IRC connection. This direct access and text-based protocol makes debugging and testing much easier.  It also allows you to take control of the bot, by manipulating the in and out files by hand, even while the bot is still running!

I did find a few places where ii was lacking.  One major issue is that non-implemented commands can be inaccessible.  ii processes input beginning with a / character as a command and has support for basics like joining(/j), parting(/l), going away(/a), and setting the topic(/t); however if the command you want to use is not implemented it will be disregarded. Sending raw-text without the / character is processed as a PRIVMSG to whichever in-file you are outputting to. Commands like MODE aren’t implemented and cannot be done as an argument to PRIVMSG directly. The only option for op’ing or voicing a user or setting a channel mode, is to have your bot ask ChanServ to do it, which on service-less networks is problematic.  I also found when using ii, that it’s best to clear the out-files before reading from them on the start-up of your bot. ii doesn’t do this itself, and can lead to your bot spamming responses to messages sent to it previously.

Overall, I really like ii as a back-end for building IRC bots. The issues I encountered were fairly minimal and in most cases have patch-less workarounds.  The ii source is clean and easy to understand, so making modifications to support extra functionality when necessary should be quick and painless (assuming you know some C).  Patches to handle tasks like IPv6 and SSL have been submitted and are located on the ii website.  I’ve written a basic python framework for a single-room bot that can read PMs and keep track of users, based on ii.  If you’re interested in playing with that code, you can download it here. (Note: the framework-bot is currently meant to run in it’s channel’s directory. )

Do you have other ideas?  Was something I wrote incorrect?  Got more information?  Let us know in the comments!

[Update: 1/7/2011]

Upon further inspection, unimplemented commands that cannot be run as arguments to PRIVMSG are available given that they do not begin with a “command letter”, such as j, l, or a (the full list can be viewed in the ii source in the proc_channels_input function.)  Any input starting with the / character and not followed by a command letter is passed directly to the server.


echo “/MODE #CHANNEL +v nick\n” >> ircdir/irc.psych0tik.net/#channel/in

About samurai

I like computers... A lot. So I tend to spend a lot of time doing varied things with them. Often you'll find me playing with Python or PHP, fighting with operating systems, ranting about some off-the-wall concept, or preparing for zombies.
This entry was posted in Reviews and tagged , , , , , , , . Bookmark the permalink.

2 Responses to Writing IRC bots using ii

  1. Pingback: psych0tik

  2. Pingback: Automating Security Analysis | psych0tik

Leave a Reply

Your email address will not be published. Required fields are marked *