IRC Bots and Message Queues
As I have recently once again become frustrated by how my IRC bot evolved into a horrible mess of code and I have decided on yet another rewrite after seeing how hook.io (Written in NodeJS) handles IRC bots I decided to take a look at implementing something similar.
I recalled that I experimented with message queues before with various pieces of other software and that a message queue might just provide the functionality that’s similar to hook.io that I wanted.
So after some researching I decided to settle on RabbitMQ, it’s fast, simple to set-up and has a nice status/admin plugin that is helpful both during development and a live environment.
I also decided to use Gevent for this rewrite rather than Twisted which I’ve always used for my previous bots. Sure asynchronous code can be written clearly, but the clarity and ease-of-use of blocking/synchronous code is just way better in my opinion. And with Gevent I can write synchronous code (And use blocking libraries) and it’ll make them async in the background (Thanks to how Python generators work).
The basic functionality version of the new bot is finished, I currently have a few node types (Processes with a certain task) implemented:
- A proxy: this just connects to an IRC server, registers and pushes any packets onto the message queue (And listens for packets to send too), so now rebooting the bot won’t make it close all connections.
- A client: does the actual IRC interaction and hands the proxy packets to send to the server.
- A logger: simply outputs all messages sent between the nodes
- A command line interface: a simple command line application that implements some basic IRC commands (PRIVMSG, JOIN, PART) to send to the client manually
It’s all very basic, the proxy and client need to be changed so that they manage multiple IRC servers, a management node will be implemented that will orchestrate everything and plugins, etc. will also be their own nodes.
Some might say this is over-engineering, I’d call it flexibility and reliability. It does what I want and it does it in a clean effective fashion. Not to forget I learn more about using message queues which seem to be gaining popularity lately.
This is still long from being a working functional IRC bot but I already feel like I am making a cleaner and more organized start, and hopefully this will be the first one that actually runs in production fairly smoothly.
~Xeross

