Domo-kun
Write your own IRC-bot with ease
Domo-kun is a minimalistic IRC-bot framework.
Domo lets you create your own IRC-bot with the functionality you need in just few minutes.
Write your custom routers and let Domo do all the work for you!
npm install domo-kun
var Domo = require('domo-kun');
var domo = new Domo(config);
domo.use(domo.basicRoutes());
domo.route('Hello domo!', function(res) {
res.send('Well hello there ' + res.nick + '!');
});
domo.connect();
Configuration
var config = {
nick: 'Domo',
userName: 'Domo',
realName: 'Domo the awesome IRC-bot',
address: 'irc.freenode.org',
modules: ['domo-url', 'domo-eval'],
channels: ['#domo'],
users: [
{
username: 'riku',
password: 'admin'
}
],
debug: true
};
- nickNickname of your bot
- userNameUsername of your bot
- realNameReal name of your bot
- addressAddress of the IRC server you want your bot to connect to
- List of modules you want to auto load
- channelsList of channels you want your bot to join after connecting to server
( note that channel password can be used in the channel string '#domo pwd123' ) - usersList of user-objects allowed to control your bot
( note that some of the built-in IRC commands requires an authenticated user ) - debugenable/disable logging
Enabling basic commands
From Domo-kun 0.2 forwards, basic routes (!join, !auth etc.) are not initialized automatically. To enable these commands you have to use domo.use to register domo.basicRoutes()
domo.use(domo.basicRoutes());
Routes
domo.route(path, callback);
For routing Domo uses a router similar to Routes.js library. Received IRC messages are matched to defined paths and the callback functions are called.
domo.route method allow you to define Sinatra style routes for received message strings. It's possible to define dynamic parameters, use regular expressions and much more.
You'll find more about Domo's routing system from Routes.js documentation
domo.route('Hello Domo!', function(res) {
res.send('Hi ' + res.nick + '!');
});
domo.route('Hello :name!', function(res) {
if(res.params.name === 'Domo') {
res.send('Hi ' + res.nick + '!');
}
});
Response object
{
params: {},
splats: [],
prefix: 'riku!riku@example.com',
nick: 'riku',
user: null,
host: 'example.com',
channel: '#domo',
message: 'hello domo!',
username: 'riku'
}
- paramsRoute parameters (see example above)
- splatsCaptured regular expression groups etc. (see Routes.js documentation)
- prefixIRC user information - self explanatory
- nickIRC user information - self explanatory
- userUser object if user is authenticated. Otherwise null.
- hostIRC user information - self explanatory
- channelChannel where message was sent
- messageReceived message
- usernameIRC user information - self explanatory
Middlewares
domo.use(middleware);
// Responds only if the user who sends the message is authenticated
domo.route('Hello Domo!', domo.requiresUser, function(res) {
res.send('Hi ' + res.nick + '!');
});
You can specify route specific middleware functions by adding them as arguments before the callback function.
Currently the only built-in middleware isdomo.requiresUser, that checks if the user who sends a message is authenticated.
Creating custom middlewares is also possible.
// Reverses received messages
var reverseMessages = function(res, next) {
res.message = res.message.split('').reverse().join('');
next();
};
domo.route('Hello Domo!', reverseMessages, function(res) {
res.send(res.message); // !omoD olleH
});
domo.use(reverseMessages);
Modules
Domo allows you to write your own modules that can be loaded on runtime without having to restart your Domo instance.
There's also a number of existing plugins out there like domo-imdb and domo-url
Modules can be loaded with the built-in !load <moduleName> command and stopped with !stop <moduleName>. Module's code is refreshed every time it's loaded so hotswapping module code is possible. Both of these commands require domo.basicRoutes().
If you are looking for an example module, take a look at domo-imdb.
Creating your own module
Modules can be constructed in a number of different ways. If module exports a property named "routes", Domo will automatically register those routes and destroy them when the module is stopped. The routes property can be either an object with path:handler pairs (Example 1) or an array of routes (Example 2).
// domo-time
module.exports.routes = {
'What time is it Domo?': function(res) {
var time = new Date().toLocaleTimeString();
res.send("It's " + time);
}
}
// domo-time with array routes syntax
module.exports.routes = [
{
path: 'What time is it Domo?',
middlewares: [],
handler: function(res) {
var time = new Date().toLocaleTimeString();
res.send("It's " + time);
}
}
]
Basic routes
From Domo-kun 0.2 forwards, basic routes are not initialized automatically. To enable these commands you have to use domo.use to register domo.basicRoutes()
domo.use(domo.basicRoutes());
- !domoPrint Domo info
- !auth <username> <password>Authenticate (Probably better to do this with private message)
- !join <channel>[:<password>]*Requires authenticationTell Domo to join channel. Can include multiple channels also !join #chan1:password #chan2 #chan3
- !part <channel>*Requires authenticationTell Domo to leave channel Can include multiple channels also !part #chan1 #chan2 #chan3
- !load <module>*Requires authenticationLoad domo modules from node_modules directory
- !stop <module>*Requires authenticationStop module and detach it from message events