neuronirc script ecosystem

In July 2011, I started an irc bot (donpdonp/neuronirc) because irc provides a simple yet powerful human-to-human and human-to-computer interface. It was built on the principle of loosely coupled, coordinated processes.

The foundation of the coordination is the redis pub/sub mechanism. Messages encoded in JSON are sent over pub/sub channels to interested listeners. There is redis support for nearly every language, therefore an extension to the bot can exist in nearly any language even though the core of the bot is in ruby.

This setup was working well but didn't go quite far enough. While new functionality or 'modules' was now possible in any language, the creation of and launching of new modules required significant administrator intervention. The users or participants in the channel could surely contribute their own useful code to the irc bot and I wanted a way to capture those contributions easily, without administrator intervention

In May of 2012, a change was committed - userspace v8. Thanks to the fantastic ruby module called therubyracer, it was simple to encapsulate a javascript interpreter inside the bot. It has enough sandboxing to make it safe to execute most any user script.

Users in an irc chatroom could now give code to the bot to extend its functionalities. I started to use it all the time because it was simple and fast to add a new command to the bot's inventory. Some script management commands were added to make it easier to list your scripts, delete one of them, and create a script from the contents of a url (usualy a github gist). Script complexity ranged from simple to complex.

Now that there are 20-something scripts inside the neuronbot (called zrobo on #pdxtech/freenode), I forget about scripts that I've wrote in the past. Many of them are periodically executing. That starts to feel like sci-fi. I can read and understand any single script, but the entire system is starting to grow beyond my ability to comprehend.

Scripts listen for messages and messages have types. Most often the type is a new line of text from an irc chatroom. That has a particular type. It was a huge leap forward when a new type of message started to be emitted once a minute. Thats a message indicating a change in time, which enables scripts to run periodically. This month scripts have the ability to emit their own messages. This lets complexity be distributed across multiple scripts. One script can be dedicated to monitoring a feed of some sort, such as the weather or a bitcoin marketplace. When conditions are right, a signal is emitted and another script can take action based on that.

Another area of exploration is to standardize the message format amongst different irc bots, and use an irc channel as a bus for messages between bots.

tags: