var properties = {
  server:   '',
  port:     9000,
  password: '',
  ssl:      false,
  nick:     ''
};

var weechat = require('weechat');
var notify = require('osx-notifier');

var raise_notification = function(from, message) {

  notify({
    type: 'info',
    title: 'Weechat',
    subtitle: from,
    message: message,
    group: 'Weechat'
  });

};

var client = weechat.connect(properties.server, properties.port, properties.password, properties.ssl, function() {

  client.on('error', function(err) {
    console.error(err);
  });

  client.on('end', function() {
    console.log('end');
  });

  client.on('line', function(line) {
    console.log(line);
    var from = weechat.noStyle(line.prefix);
    var message = weechat.noStyle(line.message);

    if (message.indexOf(properties.nick) >= 0 && from.indexOf(properties.nick) == -1){
      raise_notification(from, message);
    }
  });

});


#!/usr/bin/env node

var weechat = require('weechat'),
    notify  = require('osx-notifier'),
    client;

var properties = {
  server:   process.env.SERVER,
  port:     8001,
  password: process.env.PASSWORD,
  ssl:      false,
  nicks:    process.env.NICKS.split(',')
};

var raiseNotification = function(from, message) {
  notify({
    type: 'info',
    title: 'WeeChat',
    subtitle: from,
    message: message,
    group: 'WeeChat'
  });
};

var connect = function() {
  return weechat.connect(properties.server, properties.port, properties.password, properties.ssl, function() {
    console.log('Connected.');
  });
};

client = connect();

client.on('line', function(line) {
  var from = weechat.noStyle(line.prefix);
  var message = weechat.noStyle(line.message);

  var containsNick = properties.nicks.some(function(nick) {
    return message.indexOf(nick) !== -1;
  });
  var isPrivate = line.tags_array.indexOf('notify_private') !== -1;
  var isSelf = from === properties.nick;

  // Make sure the message is either a highlight or a PM:
  if ((!isSelf && containsNick) || isPrivate) {
    raiseNotification(from, message);
  }
});

Make it work with private messages, add env variables for stuff and refactor.
Make it work with private messages, add env variables for stuff and refactor.
