Features Download
From: Jeremy Shaw <jeremy <at> n-heptane.com>
Subject: ANN: ircbot 0.1.1
Newsgroups: gmane.comp.lang.haskell.cafe
Date: Monday 10th October 2011 22:02:22 UTC (over 5 years ago)

I have just released a new library on hackage called ircbot. (Because  
that is what Haskell really needs -- another irc bot library).


A demo app is here:


The demo is pretty non-thrilling. 98% of it is parsing command-line  
arguments, and then it calls a simple bot with two parts:

  pingPart - part that handles server PING/PONG requests
  dicePart - a simple part that lets you roll dice

Here is an example session:

 synthea: dice 3d4+12
 You rolled 3 4-sided dice with a +12 modifier: [1,3,4] => 20

The primary reason this library exists is that a long time ago, I  
needed a way to log the #happs channel. So I coded up a little logging  
bot using the irc library from hackage.

Then later I decided to fork the irc logging out of the happstack.com  
server itself and into a resuable irc bot library.

The library has the following features:

  1. a reconnect loop that tries really hard to make sure the bot  
notices if it is disconnected and tries to reconnect.

  2. a channel logging facility that automatically rolls over to a new  
log file every day.

  3. a BotMonad class and BotPartT monad which make it easy to create  
handlers for incoming messages:


Each bot part is run in its own thread. Incoming messages are  
delivered to all the parts. That is useful because some parts, like  
the seen command, need to see every incoming message, even if they do  
not actively respond to them. Because the parts are handled by  
different threads, they do not block each other.

By default, each part is single-threaded. That is because some parts  
may need to see multiple messages and see them in the order they  
originally arrived. However, a part can easily call forkIO to handle  
each incoming Message and avoid blocking when appropriate.

  4. a wrapper that let's you use Parsec to parse an incoming message.  
It is used by the dicePart:


Using parsec gives you an easy way to specify syntax errors:

  synthea: dice
 unexpected end of input; expecting dice d[+]

Future work:

1. The library is based around the old String based irc library. Would  
be nice to upgrade to something that used ByteStrings+Text+Builder.  
Practically speaking.. it's IRC. The maximum line length is 510  
characters, and the bot typically needs to handle, at most, a few  
messages per second. So, space and time issues would only be a  
practical concern if your bot is joining hundreds of channels. But,  
that is no excused not to use Text :) Perhaps the fastirc library?

2. The channel logging feature needs some minor changes so that more  
than one channel at a time can be logged

3. the bot needs to do something sane if the nick it wants is already  
in use. It should also support nick registration.

4. needs automatic help text generation

5. documentation

6. It should be possible to support dynamically reloadable plugins.  
Most of the technology exists in happstack-plugins + plugins. We just  
need to finish splitting happstack-plugins into two packages.

7. clustering support. ircbot does not have any built-in persistent  
storage. It should work fine with acid-state, SQL, etc. When acid- 
state gets multimaster replication support, it would be nice if there  
was an automatic failover system. Basically, you could have two or  
more bots in the channel using acid-state replication. Queries would  
normally be answered by the primary bot, but if the primary bot goes  
offline, the secondary bot could answer the queries instead.

8. windows support - the channel logging feature uses the unix  
package, which is not supported on Windows. The rest of the code is  
already portable.

Anyway. Enjoy!

- Jeremy
CD: 3ms