Thursday, January 06, 2005

IRC Bot 2

I stopped IRC'ing a few months ago, largely because there was a group of annoying users that made me feel like I was stuck in an extended Beavis and Butthead episode.

In any case, I prefer IM to IRC, because with IM you are just talking with one person and it is easier to focus on the conversation. With IRC, it varies from silence (nobody else is on) to cacophony (dozens of people all talking).

I told myself that about the only way I'd step back into IRC is if the channel I used to visit somehow split, and left behind the annoying users. Well, lo and behold, Breigh IM'ed me one day and told me that this exact situation occured!

So, I revamped my spare computer, and installed a different linux distribution. That computer was running Gentoo, and I decided to try Fedora because I just couldn't get a few things working under Gentoo, like sound, and I was tired of fiddling with it. Unfortunately, the Fedora install wouldn't start my network, and after digging around looking for various config files and trying a few things out, I just decided to punt and install the easiest distribution I've ever tried: Knoppix. Fundamentally, I'm not that interested in config and setup, I just want some linux distro running, so I can learn more about linux in my spare time.

Anyway, I installed Knoppix to the harddrive, updated it, and now have a spare computer to run various things on, like IRC bots.

Breigh asked if I knew much about InfoBot as she wanted to run some fun bots in the new IRC channel. Basically, bots do various automatic tasks, from holding a channel open to granting privileges. They can also respond to commands which in turn can start file transfers or answer questions. We thought it would be fun to have a bot store quotes from users, and then recall them later.

So, after a bit of work, I added those features. Previously, I added a "magic 8 ball" function, where the bot simulates the responses from the popular toy. So, I dusted off the code and added a "spin" function (spins a bottle among all the users in the channel) and "quote" functions (add/recall user quotes). It may sound all mysterious, but most of the code is pretty simple. For example, the "magic 8 ball" function is just:


private void do8Ball( String channel, String sender, String message )
{
String reply;

if ( message.length() < 8 )
{
reply = "usage: @8ball question";
sendMessage( channel, reply );
}
else
{
String question = message.substring( 7 );
int replyIndex = ( int ) ( Math.random() * eightBallReplys.length );

reply = sender + " asks " + question + " ... " + eightBallReplys[ replyIndex ];
sendMessage( channel, reply );
}
}


I'll probably let the bot sit for a while, before making further updates. I'm thinking of rewriting the entire thing in python, just as a way to learn that language. Another enhancement I could make is using a database to store quotes, which would be a fun way to learn a bit about database programming.

This has been entertaining in its own way - who says programming can't be fun?!

No comments: