2.1 KiB
2.1 KiB
irc-framework
A better IRC framework for node.js. For bots and full clients. Read the documentation.
Aims
- Lightweight
- Performant
- Very easy to get going out of the box
- Grows as needed for larger applications
- IRCv3 compliant
- Multiple (+ auto detected) encoding support
- Complete test suite
A simple and low-boilerplate framework to build IRC bots.
var bot = new IRC.Client();
.connect({
bothost: 'irc.freenode.net',
port: 6667,
nick: 'prawnsbot'
;
})
.on('message', function(event) {
botif (event.message.indexOf('hello') === 0) {
event.reply('Hi!');
}
if (event.message.match(/^!join /)) {
var to_join = event.message.split(' ');
event.reply('Joining ' + to_join + '..');
.join(to_join);
bot
};
})
// Or a quicker to match messages...
.matchMessage(/^hi/, function(event) {
botevent.reply('hello there!');
; })
Channel/buffer objects. Great for building clients
var bot = new IRC.Client();
.connect({
bothost: 'irc.freenode.net',
port: 6667,
nick: 'prawnsbot'
;
})
var buffers = [];
.on('registered', function() {
botvar channel = bot.channel('#prawnsalad');
.push(channel);
buffers
.join();
channel.say('Hi!');
channel
.updateUsers(function() {
channelconsole.log(channel.users);
;
})
// Or you could even stream the channel messages elsewhere
var stream = channel.stream();
.pipe(process.stdout);
stream; })
Middleware
function ExampleMiddleware() {
return function(client, raw_events, parsed_events) {
.use(theMiddleware);
parsed_events
}
function theMiddleware(command, event, client, next) {
if (command === 'registered') {
if (client.options.nickserv) {
var options = client.options.nickserv;
.say('nickserv', 'identify ' + options.account + ' ' + options.password);
client
}
}
if (command === 'message' && event.event.nick.toLowerCase() === 'nickserv') {
// Handle success/retries/failures
}
next();
}
}
var irc_bot = new IRC.Client();
.use(ExampleMiddleware()); irc_bot