Domo arigato, Mr. Roboto

I have always liked bots, I have written a few MediaWiki bots in other languages and the first non-trivial Perl 6 I wrote was my own Perl 6 MediaWiki bot framework (still not ready for any live-wiki editing yet). There just seems to be something about writing a program that imitates human behaviour (such as editing a wiki, or chatting on IRC) that interests me. So, given that it had been suggested a few times that #perl6 should have a bot written in Perl 6, about a month ago I looked into writing one and soon gave up. The problem was Rakudo’s IO::Socket.rev() method which would only ever return once the connection closed. This worked fine for a MediaWiki bot operating over HTTP (which can connect, disconnect, receive with no problems) but was no good for an IRC bot (which needs a constant connection). It was, however, possible to have ‘blind’ “bot” that could send messages to the channel, but as fun as that was, the bot wouldn’t be able to see PINGs from the server.

Being so close to having a Perl 6 IRC bot, I eventually come up with this hack and a non-visually challenged quux was born. That hack evolved into this patch and IRC bots were suddenly possible on Rakudo.

Just over one week later and #perl6 now has three IRC bots written in Perl 6:

Zaslon: Polls RSS feeds and announces in the channel whenever a blog it follows is updated. Zaslon also takes commands to add new blogs to follow, remove blogs or post a link to a blog. If anyone is wondering, Zaslon is named after the Zaslon radar.

pointme: Pointme is a very simple bot that posts links to projects tracked by proto. If anything it is an example of how simple an IRC bot can be. Named after hugme, the idea being that hugme embraces people (adds them to the project) while pointme points them in the right direction.

Mubot: Mubot is a karma-tracking bot, written because everyone is sick of lambdabot responding to any message that begins with an “@” or “>” (and there might be a few other trigger characters). Mubot properly supports (Multiple word)++ identifiers (lambdabot would give “word)” karma) and aliases. It is named ‘Mu’ since Mu is the letter after ‘lambda’ in the Greek alphabet.

Of course, there are some issues with Perl 6 IRC bots at the moment.

The first issue is the lack of non-blocking IO, Zaslon is the bot that suffers mainly from this problem; it can’t poll the RSS feeds while it’s receiving messages from the IRC server. This isn’t so much of a problem for bots like Mubot that only need to quickly analyse each message as it comes in, but Zaslon takes a significant amount of time to poll the feeds which means if it was checking the RSS feeds when a command was given it could take ~1 minute for it to respond. This would also be a problem if it missed a PING from the server. So the work around was to split up the IRC and RSS parts into two processes. This and the memory problem I explain below forced me into using what was probably a better solution anyway; to have the RSS part run on a crontab. rakudobug++

The second issue is memory. This was really an accidental discovery on my part. Zaslon’s proof of concept was quuxx (look at the code at your own risk…), I had it running the Rakudo revision in which my recv patch was applied. When I wrote pointme I updated the rakudo, and set both quuxx and pointme going. After a while Parrot ran out of memory on my VPS, figuring it was because I had both running on a VPS where, between Apache, MySQL et al., memory is tight, I started quuxx again and left pointme turned off. After a bit Parrot ran out of memory again. After some experimenting I filed RT #70183. As a workaround I rolled my Rakudo back to 657d55cce1f1ded33fd1f731344bd31b33099cb8 and it has been working fine.

The bots themselves also have (coding) problems, Zaslon starts spouting nonsense if the RSS feed is unavailable when it tries to access it and things break if you try to add an RSS feed that Zaslon’s very limited RSS “parser” can’t grok (or a URL that isn’t an RSS feed).

I haven’t, however, had any of the segfaults I seen with quuxx but perhaps I haven’t had any of the bots running long enough to allow any to happen.

My todo list at the moment looks something like this:

* Make HTTP::Client handle errors better
* Make Zaslon handle RSS feeds it doesn’t understand better
* Make IRC::Client bots able to read/respond to private messages
* Make IRC::Client’s highlight method able to return the nick of the person who triggered it

So that’s that. I think I might start work on an IRC::Server now ;-) (although that is blocked by RT #70045)


This entry was posted on Thursday, November 5th, 2009 at 5:45 pm and is filed under Perl6.

You can follow any responses to this entry through the RSS 2.0 feed.

You can leave a response, or trackback from your own site.

(1) Response to “Domo arigato, Mr. Roboto”

  1. The Intersect » i maeked u a shell Says:
    -

    [...] (alternative title: Too Much Time on My Hands, which goes rather nicely with my last Perl 6 post). [...]

Leave a Reply