Raoul is a project mainly written in JavaScript, based on the Unlicense license.
raoul IRC bot
Yet another useless IRC bot, written in javascript and running on node.js, and providing an SQLite or CouchDB store. You are free to provide your own store backend. This is a pretty wrong use for CouchDB but I wanted to get my hands on it.
Raoul will:
raoul depends on a few other modules, you can either install them globally:
npm install irc-js request sprintf sqlite couch-client
... or for your bot only, to do so:
cd raoul/
npm bundle
that will create a node_modules directory and compile/install the required modules.
bot.js
var raoul = require('./lib/raoul'),
exchange_watcher = require('./lib/watchers/exchange'),
translate_watcher = require('./lib/watchers/exchange'),
weather_watcher = require('./lib/watchers/exchange');
var options = {
irc: { // to pass to the internal IRC-js object
server: 'irc.freenode.net',
nick: 'mybot',
encoding: 'utf-8'
},
store: { // will use 'dummy' if not set
backend: 'couchdb',
hostname: 'localhost',
port: 5984,
db: 'mybot'
},
altnicks: ['myb0t', 'mybot_'],
autoreply: [30, 60], // Will throw a random quote between each 30-60 msgs (random)
channels: ['#mychan'],
nspassword: 'foo', // Nickserv password
ping_delay: 180000, // send ping to server every 3 minutes
timeout_delay: 60000 // consider dead if no pong within 1 minute
};
var bot = new raoul(options);
bot.watch_for(new exchange_watcher({ key: 'foo' }));
bot.watch_for(new weather_watcher({ key: 'bar' }));
bot.watch_for(new translate_watcher());
bot.connect();
The option object has the following attributes:
Watchers are easy to implement, see in the lib/watchers directory to get an idea. Basically it is an object that must have at least those 3 properties: name, regex and handler.
The handler is a function that takes 2 arguments, message, which is the message it triggered on, and match, which is the array containing the captured parts, returned by the regex you set.
The this keyword inside the handler will refer to the bot instance.
If the handler returns true, there will be no further processing, so if you want to implement something like an infobot that must catch everything, don't return true in your handler.
As watchers, you can check how to implement stores in the lib/stores directory.
The stores option attribute you pass to the bot will be passed to the store constructor, so this is where you can set your password and stuff, if needed.
Your own store must provide at least those 2 methods:
Your CouchDB database will need a _design_tools document such as:
{
"_id": "_design/tools",
"language": "javascript",
"views": {
"random": {
"map": "function(doc) {if (doc.type == 'quote' && doc.random) {emit(doc.random, doc);}}",
"reduce": "_count"
}
}
}
Create an SQLite 3 database such as:
CREATE TABLE quotes (id INTEGER PRIMARY KEY AUTOINCREMENT, quote TEXT);
In the options, setup your store such as:
store: {
backend: 'sqlite',
file: 'yourdb.db'
}
Written by Renaud Drousies
Raoul is UNLICENSED