Tennu - Modular IRC Bot Framework for Node.js
Tennu is an IRC bot framework written in Node.js
With Tennu, you create an irc client, require your plugins or subscribe to your event listeners, and then connect.
var tennu = require'tennu';var network = require'../config/myNetwork.json'; // See next sectionvar myClient = tennuClientnetwork;myClientconnect;
Before connecting, add listeners to events from irc & users, or load plugins.
// Do something when a nick, perhaps yourself, joins a channelmyClienton'join'thissaymessagechannel messageactor + " joined!";;// Do something when a user emits a command, in this case, join the specified channel.myClienton'!join'thisjoincommandargs0;;// Load a plugin.myClientinitializerequire'./yourModule';// Or just use a plugin from tennu_plugins/%f or node_plugins/tennu-%fmyClientuse'admin' 'last-seen';myClientconnect;
See https://tennu.github.io/ for the full documentation.
A network configuration object has the following properties:
- server - IRC server to connect to. Example: irc.mibbit.net
- port - Port to connect to. Defaults to 6667.
- secure - Use a TLS socket (Throws away the NetSocket)
- ipv6 - Whether you are connecting over ipv6 or not.
- localAddress - See net.Socket documentation. ;)
- capab - IRC3 CAP support. (Untested)
- password - Password for IRC Network (most networks do not have a password)
- nickname - Nickname the bot will use. Defaults to "tennubot"
- username - Username the bot will use. Defaults to "user"
- realname - Realname for the bot. Defaults to "tennu v0.3"
- auth-password - Password for identifying to services.
- nickserv - Nickname of nickserv service. Defaults to "nickserv".
- command-trigger - Command character to trigger commands with. By default, '!'.
- channels - Array of channels to autojoin. Example: ["#help", "#tennu"]
- plugins - An array of plugin names that the bot requires.
- disable-help - Disables the built-in help plugin.
Other plugins may add additional properties.
Configuration objects are JSON encodable.
The second (optional) parameter to tennu.Client is an object of factories to replace the factories that the Client uses by default.
These functions will always be called as constructors (with
The only one you will probably care about is Logger. The object returned by the Logger function must implement the following methods:
debug, info, notice, warn, error, crit, alert, emerg
Base Tennu will only use debug through error, but other plugins and event emitters may use crit through emerg.
Tennu follows SemVer. Tennu will have breaking changes in the future, and many updates will be breaking updates, so expect to see the major version go up to pretty high numbers. The alternative was to have verisons 0.16.x at some point, and that's just silly. Tennu is usable today, might as well call it post-1.0, even if it's not 'feature complete'.
Note: Tennu uses a custom event handler. Listeners are placed at the end of the node event queue (with setImmediate), insead of happening in the same turn. Errors are currently logged to console, but otherwise swallowed.
Commands and Messages that have a channel property take a return value. Currently, the return value must be a string or array that is then said to the channel the message originated in.
// Simple echobot.tennuon'privmsg'return privmsgmessage;;// Equivalent to:tennuon'privmsg'tennusayprivmsgchannel privmsgmessage;;
Subscribing to events in Tennu is more flexible than most event listeners.
You register a single handler on multiple events at once by separating the events with a space,
.on("x y", fn) is equivalent to
.on('x', fn); .on('y', fn). Furthermore, an object
can be passed, where each key is passed as the first parameter and its value, the second.
// Exampleson"irc_event" listeneron"!user-command" listeneron"join quit" listeneron"part": part_listener"join": join_listener"!hi !bye": talk_listener
You can also unsubscribe non-once events with
off, taking the same parameters as
Listeners are passed either a message or command object.
Messages are passed by irc events.
Messages are immutable, as are their args. Make sure to copy the args array before trying to manipulate it.
All messages have the following fields:
- prefix - The prefix is either a hostmask of the format "nickname!username@hostname", or the server you are connected to.
- command - Message command type. For example, 'privmsg' or 'nick'.
- params - Array of sent parameters.
- tags - IRC3 tags sent with message.
Some messages have extended information. See Message Properties.
Commands are passed for user commands.
Commands are an extension of Messages with the command type of 'privmsg'. They have all properties, plus the following properties:
- args - Array of words after the command name.
- command - The command name.
For example, a command of "!do-it ARG1 ARG2" will have args be ["ARG1", "ARG2"] and command be 'do-it'.
All of the following are methods on Tennu that can be used once connected.
These methods are also available on the client's 'out' property. In Tennu 0.9.0, the 'out' property will go away, and the 'actions' plugin will export these methods.
- channel is either a channel ("#chan") or a user ("nick").
- message is either a string or array of strings. Given an array, say each individual element on its own line.
Has the bot say the message(s) to the specific channel/user.
/* Output (IRC)(botnick) This is a message!*/tennusay'#example' "This is a message!";/* Output (IRC)(botnick) Hi there.(botnick) Bye there.*/tennusay'#example' "Hi there." "Bye there.";
As per say, but as an action (/me)
/* Output (IRC)botnick does something!*/tennuact'#example' "does something!";
tennuctcp'havvy' 'ping' 'PINGMESSAGE';
Change the bots nickname.
Joins the specified channel.
tennujoin"#tennu";tennujoin"#keyed-channel channel-key";tennujoin"#chan1,#chan2";tennujoin"0"; // Part all channels.
Parts the specified channel with the given reason.
Quits the server with the given reason.
Server is optional, and you'll probably not need it. Look at RFC 1459 for what benefit it gives you.
users is either a string or an array of strings.
Retrieves the userhost of the user(s).
For actions that are lacking a command, you can use raw to perform them. You must either pass an array of arguments (and the multiword argument must be in a single index without the colon) or pass the full string.
If you find yourself using raw(), please file an issue.
As raw(message), but the arguments are passed through util.format() first.
Tennu has its own (optional to use) plugin system. You can read about it at https://github.com/havvy/tennu-plugins/.
You may access the plugin system's methods via the Client.plugins property or by using one of the following methods:
See Getting Started.
Only the help plugin is currently fully implemented.
Handles the two commands "!commands" and "!help".
If you don't want this functionality, set
true in your configuration object.
Unimplemented. Currently being worked on by Dan_Ugore.
This plugin has a single method exported: isIdentifedAs(nickname, nickname_identified, callback)
Information about the server. For now, the only thing this plugin offers is a capabilities map listing the information from the 005 raw numeric.
var server = tennuuse"server";console.logutilinspectservercapabilities;
Tennu comes with a command line utility for starting Tennu bots with configuration located in a JSON file. The executable is called "tennu".
The tennu command takes two optional argument, -v (--verbose) and -d (--debug),
for adding a Logger that logs all non-debug messages to the console. Add
also log debug messages.
See the contributors.md file for specific ways you can help, if you're just looking for any way to help.
test directories are all auto-generated files,
with the actual source in subdirectories in the
bin directory contains the executables that the package provides. Right now this
is only the 'tennu' program described in the Command Line Utility section.
examples directory contains example bots, mainly used for integration testing.
This command will rebuild the test files and then run the test suite.
Between all projects (tennu, tennu-plugins, irc-socket, after-events), there are over 100 tests, but more are always appreciated, especially if they are failing with an actual bug. ;)
npm run-script build