<commit_before>var irc = require('irc'),
  util = require('util');

function Bot(host, channel, opts) {
  opts = opts || {};
  this.nick = opts.nick || 'nestor';
  this.host = host;
  this.channel = '#' + channel;
}

Bot.prototype.connect = function (commands) {
  var self = this;

  process.on('SIGINT', function () { self.disconnect(); });
  process.on('SIGTERM', function () { self.disconnect(); });

  console.log('Connecting to %s as %s', this.host, this.nick);
  this.client = new irc.Client(this.host, this.nick);

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

  this.client.addListener('message' + this.channel, function (from, message) {
    if (message.match(new RegExp('^' + self.nick))) {

      var parts = message.split(' '),
        command = parts[1],
        args = parts.slice(2);

      if (command === undefined) {
        self.say('Usage: %s <command> <arg1> ... <argN>', self.nick);
      } else if (commands[command]) {
        commands[command].apply(self, args);  
      } else {
        self.say('Command \'' + command + '\' is not supported');
      }
    }
  });

  setTimeout(function () {
    console.log('Joining channel %s', self.channel);
    self.client.join(self.channel);
  }, 1000);

};

Bot.prototype.disconnect = function () {
  console.log('Leaving channel %s and disconnecting', this.channel);
  this.client.part(this.channel);
  process.exit(0);
};

Bot.prototype.say = function () {
  var message = util.format.apply(this, arguments);
  this.client.say(this.channel, message);
};

Bot.prototype.handleCb = function (successCb) {
  var self = this;
  return function (err, result) {
    if (err) {
      console.error(err.message);
      self.say(err.message);
    } else {
      successCb(result);<commit_msg>Swap Bot constructor and connect arguments for correctness.<commit_after>var irc = require('irc'),
  util = require('util');

function Bot(commands) {
  this.commands = commands;
}

Bot.prototype.connect = function (host, channel, opts) {
  opts = opts || {};
  this.nick = opts.nick || 'nestor';
  this.channel = '#' + channel;

  var self = this;

  process.on('SIGINT', function () { self.disconnect(); });
  process.on('SIGTERM', function () { self.disconnect(); });

  console.log('Connecting to %s as %s', host, this.nick);
  this.client = new irc.Client(host, this.nick);

  this.client.addListener('error', function (err) {
    console.error('Error: ', err);
  });

  this.client.addListener('message' + this.channel, function (from, message) {
    if (message.match(new RegExp('^' + self.nick))) {

      var parts = message.split(' '),
        command = parts[1],
        args = parts.slice(2);

      if (command === undefined) {
        self.say('Usage: %s <command> <arg1> ... <argN>', self.nick);
      } else if (self.commands[command]) {
        self.commands[command].apply(self, args);  
      } else {
        self.say('Command \'' + command + '\' is not supported');
      }
    }
  });

  setTimeout(function () {
    console.log('Joining channel %s', self.channel);
    self.client.join(self.channel);
  }, 1000);

};

Bot.prototype.disconnect = function () {
  if (!this.client) {
    console.error('Not connected yet, bot#connect must be called first');
  } else {
    console.log('Leaving channel %s and disconnecting', this.channel);
    this.client.part(this.channel);
    process.exit(0);
  }
};

Bot.prototype.say = function () {
  if (!this.client) {
    console.error('Not connected yet, bot#connect must be called first');
  } else {
    var message = util.format.apply(this, arguments);
    this.client.say(this.channel, message);
  }
};

Bot.prototype.handleCb = function (successCb) {
  var self = this;
  return function (err, result) {
    if (err) {
      console.error(err.message);
      self.say(err.message);
    } else {
      successCb(result);
{'fraction_non_alphanumeric': 0.17663744198040227, 'fraction_numerical': 0.0041258380608561115, 'mean_word_length': 3.170967741935484, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1937297', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1245, 'n_words': 273}