In this tutorial, we will be creating a bot that responds to a
!givemeblt command. This command will
give the requesting user a juicy BLT for their troubles.
From this, you will learn a few useful things:
- How to install Tennu
- How to create a plugin with commands
- How to start your bot
Note: Tennu is beta-quality software. There are rough edges, and updates will often bring backwards-incompatible changes. Be prepared to either stay on the version you are using, or to change your code when updating. Likewise, Tennu is not feature complete.
Tennu is a Node.js framework. You must have Node.js installed to use Tennu.
Create a new Node.js project. If you've never done this before, here is a simple process for doing so:
- Create a directory to store your project.
- Open up the directory in your console.
npm initand answer its questions.
npm install tennu --save.
Your project should now have a
We will be adding two more items:
- All configuration data for your bot will be located in this file.
- A directory that will contain all of your custom plugins.
We will start with the configuration file. Take this
JSON, and save it in
You will want to change these values for your bot, specifically `server` and `channels`.
You can have your bot identify to services (the service named by `nickserv`) by setting the `auth-password` option to the password. You must first register the nickname on the server. See here for more details.
If you want the commmand trigger to be a different character, say
@ instead of
!, change the `command-trigger` property.
The plugins property already contains a plugin,
blt. We haven't
written it yet, but this will be its name. Any plugins you want to load,
including their dependencies, must be listed in this array, not counting
Tennu's default plugins which provide the base functionality of the bot.
Writing the BLT Module
In the previous section, we named the plugin
BLT. As such,
our plugin will be located at
Here are the contents of
We send an action to the server in the channel the command came from giving the BLT to the nickname the command originated from.
If you have never used Node.js before, the final line may confuse you.
It just means that the Node module is exporting the object at
BLTPlugin. If it was not there, Tennu (or any node module)
would not be able to access the plugin.
Given this example, every Tennu Plugin file should look minimally like this:
Inside a plugin's source code, the command trigger is always
"!". Do not change it. Changing the command trigger in
config.json is sufficient.
The Tennu Plugin Factory is an object with a single property,
This property contains a function that takes two
imports. The client is
the reference to Tennu, and your way of accessing all of the functionality
the library provides outside of the hooks described here. The imports
object contains the exports properties of plugins that you require.
init function returns an object, known as the plugin
instance, with various properties, all optional:
- Values that are passed to other plugins when they require your plugin.
- This is an object where the property names are the message and command types to listen to, and the functions are the handlers for that message or command type. To distinguish between message and commmand types, commands are prefixed with a `!`. This prefix is separate from the bot's command prefix set in the configuration object.
This is a hook for the help plugin to
provide help for your commands and other topics. Note the usage of
instead of a hard-coded command handler here.
- This is also a hook for the help plugin to list the commands provided by your bot.
- Mentioned here for completeness, see hooks.
Comparing this to our bot, our bot does not export any values, and has one command handler that is documented. It does not do any special initialization.
Running Your Bot
Tennu comes with a command line utility for starting bots.
From the command line, in your project directory, utter this incantation:
./node_modules/.bin/tennu config.json -v
This command says run your tennu bot with the configuration located at
config.json with verbose output.
If you want your bot not to log to the console, leave off the -v flag.
For extra utility, put this command into the scripts property of
Now you can just type
npm start to start your bot.