Drinking tea at NAP with Bungle, Zippy and George

A few of us at NAP take tea drinking very seriously.

Personally, I’ve instigated and run tea rounds throughout my career, but it’s only while I’ve been at NAP that I’ve realised what’s been missing. While discussing whose round was next in our IRC chat room #tea, we came up with the idea of a tea bot. The notion of this is not completely novel, and there are apps available to determine who should make the next round. The trouble was, we felt they lacked the rules, features and ease of use that we wanted.

Some of the features we wanted included:

  • Easy maintenance of tea rounds
  • Fair tea-making system
  • Element of surprise
  • Able to deal with people being away temporarily
  • Support for volunteering to make a round

So, we created Zippy, Bungle and George (depending on who in the tea round is running the bot). Adam got us started, Pete made significant contributions and I wrote some tests.

How did we implement this? Well, when Zippy, Bungle or George enter the tea room, they randomly put all the users into an array. Issuing the “!tea” command takes the first name off the front of the array, and a message appears stating who called “!tea” and who’s going to make the round. This name is then put to the end of the array.

As previously mentioned, we wanted to be able to volunteer. Issuing the “!tea volunteer” command announces that you’re going to make tea (and tries to give you positive karma), then takes your name out of the queue and puts it to the end.

We initially implemented the bot such that the queue would be re-shuffled every morning. This added an element of surprise, but as the ratio of people to brews we drink in a day increased, it meant people could get away with not making tea for quite a while. Which, of course, is unfair.

There is also a command to view the queue, “!tea status”, but this is frowned upon as it removes the element of surprise (we implemented this mainly for debugging).

In future, we’d like to be able to turn the shuffling and status features on or off.

Dealing with people who were temporarily away was a little tricky. We wanted to keep a complete history of people who had been called in case, for example, two people called in a row were in a meeting. We had a few problems with this, and found that just dealing with one person being away was the easiest solution.

The command “!tea away” declares the next name at the front of the queue to make tea and then swaps their position with the last person to be called.

The main challenge with writing the tests was to fake the call through Bot::BasicBot::Pluggable that fetches all the members of the tea room. This was done by mocking the method call like this:

    my $module = new Test::MockModule('Bot::BasicBot::Pluggable');
    $module->mock('pocoirc', sub {
        my $mock_pocoirc = Test::MockObject->new();
        $mock_pocoirc->set_list( 'channel_list', @test_users );
        return $mock_pocoirc;

This meant we could test the “!tea” command, proving that users were correctly moved around the queue.

We can also test the “!tea away” command this way. Unfortunately, we couldn’t write a test for “!tea volunteer”, because calls in tests are still done as the bot (we haven’t gotten round to faking a user and having them make a call). As the bot doesn’t feature in the queue, its name can’t be moved around.

There are some other commands we’ve thought of adding. For example:

  • Keeping track of who currently has biscuits. We’re quite good at just getting biscuits, so a  “!biccies om-nom” command would be fun!
  • Configurable tea-round rules. We have some rules, but these should be changeable for each bot administrator.

Adam has put the code on github and CPAN, so feel free to have a play and contribute.

Note: This code was not released by the NET-A-PORTER Open Source Software group; it’s just a bit of fun a few of us had in our own time.

Print Friendly

Leave a Reply