weechat

WeeChat Relay Protocol

WeeChat.js

WeeChat Relay Protocol module for Node.js

npm install weechat

.connect(host, port, password, [callback])
Connect to WeeChat:
(host, port password, ssl, callback)

var client = weechat.connect('localhost', 8000, 'test', false, function() {
    console.log('Connected!');
});

Or with SSL support:

var client = weechat.connect('localhost', 9001, 'test', true, function() {
    console.log('Connected!');
});

.send(message, [callback])
Send messages to WeeChat:

client.send('input irc.freenode.#weechat hello guys and girls!');
 
client.send('info version', function(version) {
    console.log(version.value);
});

.on([type], callback) Listeners, when an even occurs in WeeChat:

client.on('_buffer_line_added', function(line) {
    console.log('Got line', line);
});
 
client.on(function() {
    console.log('Anything happened', arguments);
});
 
client.on('line', function(line) {
    console.log('Got line', line);
});

Built in listeners
There are some built in aliases making listeners easier to add:
line: New line added
open: Buffer is opened
close: Buffer is closing
renamed: Buffer is renamed
localvar: Local var is added
title: Title (topic) is changed for a buffer
nicklist: Nicklist

The module return only pure WeeChat strings, including coding for colors.
Calling weechat.style(line); will return an array of parts, like this:

[ { text: 'Hello', fg: 'dark cyan', bg: undefined, attrs: [] },
  { text: 'world!' } ]

fg is foreground color, bg is background color, attrs is an array of attributes, such as underline.

The module supports stripping these codes away, returning a plain string, like this:

weechat.noStyle(line);
var weechat = require('weechat');
 
var client = weechat.connect('localhost', 8000, 'test', function() {
    console.log('Connected!');
 
    client.send('info version', function(version) {
        console.log(version.value);
    });
});
 
client.on('error', function(err) {
    console.error(err);
});
 
client.on('end', function() {
    console.log('end');
});
 
client.on('line', function(line) {
    var from = weechat.noStyle(line.prefix);
    var message = weechat.noStyle(line.message);
 
    console.log(from, message);
});

MIT License (c) Eirik Brandtzæg