slate-irc is a module by that part of the recently released open source IRC client called Slate and is a general purpose IRC client with simple plugin system.
1
|
npm install slate-irc |
Usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
var irc = require( 'slate-irc' ); var net = require( 'net' ); var stream = net.connect({ port: 6667, host: 'irc.freenode.org' }); var client = irc(stream); client.on( 'notice' , function (notice) { console.log(notice.message); }); client.nick( 'npmawesome-test' ); client.user( 'npmawesome-test' , 'Alex Gorbatchev' ); client.join( '#flood' ); client.names( '#flood' , function (err, names) { if (err) throw err; names.sort(); console.log(names.join( 'n' )); client.quit(); }); |
Plugins
Plugins are simply functions that accept the IRC client as an argument. With this you can define methods, listen on events and interact with the client. For example here’s a logger plugin that outputs to stdout:
1
2
3
4
5
6
7
|
function logger() { return function (irc) { irc.stream.pipe(process.stdout); } } client.use(logger()); |
Here’s a slightly more complex example of a PONG plugin responding to PING messages:
1
2
3
4
5
6
7
8
|
function pong() { return function (irc) { irc.on( 'data' , function (msg) { if ( 'PING' === msg.command) irc.write( 'PONG :' + msg.trailing); }); } } |
Closing Thoughts
slate-irc can serve as a core of a regular IRC client or you can write an IRC bot for your team chat. Checkout the github page for full documentation.