Adventures with Errbot, Part II

On Friday nights, I install plugins for bots and blog about it.
13 November 2015

In Part I of Adventures with Errbot, I wrote about installing and configuring Errbot to use with a Jabber server. Now let’s look at installing plugins for Errbot.

There is a list of over 200 plugins for Errbot. You can ask the bot about available plugins with !repos command. The command may take a few moments to run, but the list it generates is much shorter. From that list, I picked err-time, so that my bot (Bender), could tell me what time it is in different cities around the world.

Install a plugin

The command to install a plugin is !repos install plugin-source, where plugin-source can be the plugin name (like err-time) or a git repository (https://github.com/gbin/err-time). For plugins listed with the !repos command, you can use the plugin name.

Plugins can only be installed by opening a direct chat to the bot. If you try to install a plugin in a group chat the bot will tell you as much:

You cannot administer the bot from a chatroom Bender: "You cannot administer the bot from a chatroom, message the bot directly."

Got it. I opened a chat with Bender, and tried the install command again. Bender replied:

This command requires bot-admin privileges.

Hm, but I did list my username (alimac@jabberserver.tld) as an admin in the configuration file. I tried a few other variations with no success.

Finally, I found the !whoami bot command and asked Bender who I was:

┏━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┓
┃ key      ┃ value                ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━┩
│ person   │ dev@jabberserver.tld │
├──────────┼──────────────────────│
│ nick     │ dev                  │
├──────────┼──────────────────────│
│ fullname │ None                 │
├──────────┼──────────────────────│
│ client   │ alimac               │
└──────────┴──────────────────────┘
• string representation is 'dev@jabberserver.tld/alimac'
• class is 'XMPPMUCOccupant'

Well, this is strange. The bot thinks I am the room. I updated the configuration file:

BOT_ADMINS = ('dev@jabberserver.tld',)

and now I was able to give admin commands to the bot in private chat.

I happened to use a chat client on another computer later, where the !whoami command returned alimac@jabberserver.tld. I added both to BOT_ADMINS.

The reason for these differences is caused by how you initiate a chat with the bot. If you start the private chat by clicking on the bot’s name in a group chat, your identity is set to room@jabberserver.tld. If, on the other hand, you add the bot to your contact list and start the chat by clicking on the contact list entry, your identity is set to username@jabberserver.tld.

Plugin dependencies

I ran !repos install err-time again:

Some plugins are generating errors:
You need those dependencies for /var/lib/err/plugins/err-gitbot: pytz
Plugins reloaded without any error.

On the server where I installed Errbot, I ran sudo pip install pytz. Back in the chat room, I could now ask Bender what time it was in various places with !time city-name:

Asking bot what time it is Testing the err-time plugin.

Installed plugins

You can find out which plugins are installed by asking !status plugins:

Plugins

┏━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Status ┃ Name           ┃
┡━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ A      │ ACLs           │
├────────┼────────────────┤
│ A      │ Backup         │
├────────┼────────────────┤
│ A      │ ChatRoom       │
├────────┼────────────────┤
│ A      │ DnsUtils       │
├────────┼────────────────┤
│ A      │ Health         │
├────────┼────────────────┤
│ A      │ Help           │
├────────┼────────────────┤
│ A      │ Kudos          │
├────────┼────────────────┤
│ A      │ Plugins        │
├────────┼────────────────┤
│ A      │ TimeBot        │
├────────┼────────────────┤
│ A      │ Utils          │
├────────┼────────────────┤
│ A      │ VersionChecker │
├────────┼────────────────┤
│ A      │ WeatherBot     │
├────────┼────────────────┤
│ C      │ Webserver      │
└────────┴────────────────┘
 A = Activated, D = Deactivated, B = Blacklisted, C = Needs to be configured

As you can see, I installed a few other plugins.

WeatherBot

This plugin allows me to ask the bot about the weather in various places with !weather location, where location can be a city or country.

After installing the plugin (!repos install err-weather), it needs to be configured with an API key from OpenWeatherMap and optionally, the temperature units (Celsius or Fahrenheit).

Once you get an API key, configure WeatherBot using the following command:

!plugin config WeatherBot
{'api_key': '1ba5cf124541ba5cf12454', 'units': 'imperial'}

Then, ask about the current weather in say, Fairbanks, Alaska:

!weather fairbanks
Found it! it looks like the forecast is 'overcast clouds'
Here’s some more info:
Location: Fairbanks, US at 2015-11-07 16:10:20
Temperature: 23.61F [ low: 23.61F \ high: 23.61F]
Humidity: 92%
Wind: 268.5 5.44 m/s
Pressure: 989.64hP

Kudos

Another nice plugin to have is one that gives virtual thanks or praise to others. But, what are kudos?

In the 19th century, kudos entered English as a singular noun, a transliteration of a Greek singular noun kŷdos meaning “praise or renown.” - Dictionary.com

To install this plugin all you need is !repos install https://github.com/sijis/err-kudos.git.

Once installed, you can give kudos with username++:

Bender++

And check "kudo points" with !kudos username:

!kudos Bender
Bender has 4 kudo points.

DnsUtils

The DnsUtils plugin gives us the ability to run !dig, !host and !nslookup right in the chat. Use !repos install err-dnsutils to install the plugin.

Now you can run DNS lookup commands in the chat:

!host 8.8.8.8
8.8.8.8.in-addr.arpa domain name pointer google-public-dns-a.google.com.

And that’s all for now. In Part III, I will tackle creating my own plugin for Errbot.

Was this guide useful? Did you notice any mistakes? Tell me.

This post is part of a series, Adventures with Errbot: