<commit_before>
/**
 * Module dependencies.
 */

var debug = require('debug')('slate-irc:names');
var utils = require('../utils');

/**
 * Names lookup plugin.
 *
 *    client.names('#channel', function(err, names){
 *      console.log(names);
 *    });
 *
 * TODO: retain @ / +
 *
 * @return {Function}
 * @api public
 */

module.exports = function(){
  return function(irc){
    var map = {};

    irc.names = names;
    irc.nameCallbacks = {};

    irc.on('data', function(msg){
      switch (msg.command) {
        case 'RPL_NAMREPLY':
          var chan = msg.params.split(/ [=@*] /)[1].toLowerCase();
          var names = msg.trailing.replace(/[@+]/g, '').split(' ');
          map[chan] = map[chan] || [];
          map[chan] = map[chan].concat(names);
          debug('add %s %j', chan, names);
          break;

        case 'RPL_ENDOFNAMES':
          var chan = msg.params.split(' ')[1];
          debug('emit "names" for %s', chan);
          var e = { channel: chan, names: map[chan] };
          var cb = irc.nameCallbacks[chan];
          
          if (cb) cb(e)
          else irc.emit('names', e);
          
          delete map[chan];
          break;
      }
    });
  }
}

/**
 * Fetch names for `channel` and invoke `fn(err, names)`.
 *
 * @param {String} channel
 * @param {Function} fn
 * @api public
 */

function names(channel, fn) {
  var self = this;

  this.nameCallbacks[channel] = function(e){
    delete self.nameCallbacks[channel];
    fn(null, e.names);
  };

  this.write('NAMES ' + channel);
}<commit_msg>fix casing normalization in names plugin method<commit_after>
/**
 * Module dependencies.
 */

var debug = require('debug')('slate-irc:names');
var utils = require('../utils');

/**
 * Names lookup plugin.
 *
 *    client.names('#channel', function(err, names){
 *      console.log(names);
 *    });
 *
 * TODO: retain @ / +
 *
 * @return {Function}
 * @api public
 */

module.exports = function(){
  return function(irc){
    var map = {};

    irc.names = names;
    irc.nameCallbacks = {};

    irc.on('data', function(msg){
      switch (msg.command) {
        case 'RPL_NAMREPLY':
          var chan = msg.params.split(/ [=@*] /)[1].toLowerCase();
          var names = msg.trailing.replace(/[@+]/g, '').split(' ');
          map[chan] = map[chan] || [];
          map[chan] = map[chan].concat(names);
          debug('add %s %j', chan, names);
          break;

        case 'RPL_ENDOFNAMES':
          var chan = msg.params.split(' ')[1];
          debug('emit "names" for %s', chan);
          var e = { channel: chan, names: map[chan] };
          var cb = irc.nameCallbacks[chan];
          
          if (cb) cb(e)
          else irc.emit('names', e);
          
          delete map[chan];
          break;
      }
    });
  }
}

/**
 * Fetch names for `channel` and invoke `fn(err, names)`.
 *
 * @param {String} channel
 * @param {Function} fn
 * @api public
 */

function names(channel, fn) {
  var self = this;
  channel = channel.toLowerCase();

  this.nameCallbacks[channel] = function(e){
    delete self.nameCallbacks[channel];
    fn(null, e.names);
  };

  this.write('NAMES ' + channel);
}
{'fraction_non_alphanumeric': 0.18415213946117273, 'fraction_numerical': 0.0012678288431061807, 'mean_word_length': 2.2302968270214945, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6918900', 'n_tokens_mistral': 1061, 'n_tokens_neox': 1035, 'n_words': 236}