<commit_before>var Client = require('irc').Client;
var Duplex = require('stream').Duplex;
//var log = require('logule').init(module);

// opts.noChan, opts.answerPms, opts.allErrors
function IrcStream(server, name, opts) {
  if (!(this instanceof IrcStream)) {
    return new IrcStream(server, name, opts);
  }
  Duplex.call(this, {objectMode: true});
  opts = opts || {};

  // keep the bot instance public if people want to get at it
  this.bot = new Client(server, name, opts);
  if (!opts.allErrors) {
    this.bot.addListener('error', function () {}); // never usually care about errors
  }
  this.chan = opts.channels[0];

  // respond directly - in channel - to anything matching chanReg
  if (!opts.noChan) {
    var chanReg = new RegExp('^' + name + '[\\s,\\:](.*)');
    this.bot.addListener('message', function (from, to, msg) {
      if (!chanReg.test(msg)) {
        return; // message not for me
      }
      var content = msg.match(chanReg)[1].trim();
      if (!content) {
        return; // empty statement
      }
      if (content) {
        var o = {user: to + ':' + from, name: from, message: content};
        //log.trace("IrcStream departure Chan: %j", o);
        this.push(o);
      }
    }.bind(this));
  }
  // optionally listen for pms
  if (opts.answerPms) {
    this.bot.addListener('pm', function (nick, msg) {
      var o = {user: nick, name: nick, message: msg};
      //log.trace("IrcStream departure PM: %j", o);
      this.push(o);
    }.bind(this));
  }
}
IrcStream.prototype = Object.create(Duplex.prototype);

IrcStream.prototype._write = function (obj, enc, cb) {
  //log.trace("IrcStream arrival: %j", obj);
  if (obj.user == undefined || obj.message == undefined) {
    throw new Error("Improper object written to IrcStream");
  }
  if (!obj.user || obj.user.indexOf(':') < 0) {
    this.bot.say(obj.user, obj.message);
  }
  else {
    var split = obj.user.split(':');
    var chan = split[0];
    var user = split[1];
    // if multiline message in chan - only highlight on first line
    if (this.lastUser === obj.user) {
      this.bot.say(chan, obj.message);
    }
    else {
      this.bot.say(chan, user + ': ' + obj.message);
    }
    this.lastUser = obj.user;
  }
  cb();
};

IrcStream.prototype._read = function () {};

module.exports = IrcStream;
<commit_msg>listen on the nick we are given, not the one we wanted<commit_after>var Client = require('irc').Client;
var Duplex = require('stream').Duplex;
//var log = require('logule').init(module);

// opts.noChan, opts.answerPms, opts.allErrors
function IrcStream(server, name, opts) {
  if (!(this instanceof IrcStream)) {
    return new IrcStream(server, name, opts);
  }
  Duplex.call(this, {objectMode: true});
  opts = opts || {};

  // keep the bot instance public if people want to get at it
  this.bot = new Client(server, name, opts);
  if (!opts.allErrors) {
    this.bot.addListener('error', function () {}); // never usually care about errors
  }

  // respond directly - in channel - to anything matching chanReg
  var registerChanHandler = function () {
    if (!opts.noChan) {
      var chanReg = new RegExp('^' + name + '[\\s,\\:](.*)');
      this.bot.addListener('message', function (from, to, msg) {
        if (!chanReg.test(msg)) {
          return; // message not for me
        }
        var content = msg.match(chanReg)[1].trim();
        if (!content) {
          return; // empty statement
        }
        if (content) {
          var o = {user: to + ':' + from, name: from, message: content};
          //log.trace("IrcStream departure Chan: %j", o);
          this.push(o);
        }
      }.bind(this));
    }
  }.bind(this);

  this.bot.addListener('registered', function (data) {
    name = data.args[0];
    registerChanHandler(); // will listen on the name given
  });

  // optionally listen for pms
  if (opts.answerPms) {
    this.bot.addListener('pm', function (nick, msg) {
      var o = {user: nick, name: nick, message: msg};
      //log.trace("IrcStream departure PM: %j", o);
      this.push(o);
    }.bind(this));
  }
}
IrcStream.prototype = Object.create(Duplex.prototype);

IrcStream.prototype._write = function (obj, enc, cb) {
  //log.trace("IrcStream arrival: %j", obj);
  if (obj.user == undefined || obj.message == undefined) {
    throw new Error("Improper object written to IrcStream");
  }
  if (!obj.user || obj.user.indexOf(':') < 0) {
    this.bot.say(obj.user, obj.message);
  }
  else {
    var split = obj.user.split(':');
    var chan = split[0];
    var user = split[1];
    // if multiline message in chan - only highlight on first line
    if (this.lastUser === obj.user) {
      this.bot.say(chan, obj.message);
    }
    else {
      this.bot.say(chan, user + ': ' + obj.message);
    }
    this.lastUser = obj.user;
  }
  cb();
};

IrcStream.prototype._read = function () {};

module.exports = IrcStream;

{'fraction_non_alphanumeric': 0.16936641377896247, 'fraction_numerical': 0.002050440844781628, 'mean_word_length': 2.7465437788018434, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5579865', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1593, 'n_words': 429}