<commit_before>var serverHost = '127.0.0.1',
    serverPort = 6668,
    serverPass = '*',
    botNick = 'lousybot',
    joinChannels = [ '#test' ],
    pluginDir = './plugins',

    IRC_MESSAGE_END = '\r\n',

    fs = require('fs'),
    net = require('net'),
    spawn = require('child_process').spawn;

function formatIrcMessage(command, text) {
    return command + ' ' + text + IRC_MESSAGE_END;
}

function parseIrcMessage(s) {
    console.log('parse ' + s);

    var match = s.match(/(?::(.+?) )?(.+?) (.*)/),
        parsed = {
            prefix  : match[1],
            command : match[2],
            params  : match[3].split(' ')
        };

    console.log(parsed);

    return parsed;
}

function loadPlugins(path) {
    var exp,
        plugin,
        pluginPath;

    fs.readdirSync(path).forEach(function (file) {
        if (file.match(/\.js$/)) {
            pluginPath = path + '/' + file;
            console.log('require ' + pluginPath);
            plugin = require(pluginPath);

            for (exp in plugin) {
                conn.addListener(exp, plugin[exp]);
            }
        }
    });
}

var conn = net.createConnection(serverPort, host=serverHost);
conn.messageBuffer = '';

conn.sendMessage = function (command, text) {
    var formatted = formatIrcMessage(command, text);

    console.log('send ' + formatted);
    this.write(formatted);
};

conn.privmsg = function (to, message) {
    this.sendMessage('PRIVMSG', to + ' :' + message);
};

conn.addListener('connect', function () {
    this.sendMessage('PASS', serverPass);
    this.sendMessage('NICK', botNick);
    this.sendMessage('USER', botNick + ' * * ' + botNick);
});

conn.addListener('data', function (buffer) {
    var connection;

    console.log('receive ' + buffer.toString());
    this.messageBuffer += buffer.toString();

    if (this.messageBuffer.match(new RegExp(IRC_MESSAGE_END + '$'))) {
        connection = this;
        this.messageBuffer.split(IRC_MESSAGE_END).forEach(function (message) {
            var parsedMessage;
            if (!(message === '')) {
                parsedMessage = parseIrcMessage(message);
                connection.emit(parsedMessage.command, parsedMessage);
            }
        });
        this.messageBuffer = '';
    }
});

// spawn a child process and call lineCallback for each line of its stdout
conn.spawn = function (command, args, lineCallback) {
    var child = spawn(command, args),
        buffer = '',
        lastLine,
        lines;

    child.stdout.on('data', function (data) {
        lines = (buffer + data).split('\n');
        buffer = lines.pop();
        lines.forEach(lineCallback);
    });

    return child;
};

// IRC command listeners

// welcome
conn.addListener('001', function () {
    var connection = this;

    joinChannels.forEach(function (channel) {
        connection.sendMessage('JOIN', channel);
    });
});

conn.addListener('PING', function (m) {
    this.sendMessage('PONG', m.params[0]);
});

conn.addListener('PRIVMSG', function (m) {<commit_msg>unused variable<commit_after>var serverHost = '127.0.0.1',
    serverPort = 6668,
    serverPass = '*',
    botNick = 'lousybot',
    joinChannels = [ '#test' ],
    pluginDir = './plugins',

    IRC_MESSAGE_END = '\r\n',

    fs = require('fs'),
    net = require('net'),
    spawn = require('child_process').spawn;

function formatIrcMessage(command, text) {
    return command + ' ' + text + IRC_MESSAGE_END;
}

function parseIrcMessage(s) {
    console.log('parse ' + s);

    var match = s.match(/(?::(.+?) )?(.+?) (.*)/),
        parsed = {
            prefix  : match[1],
            command : match[2],
            params  : match[3].split(' ')
        };

    console.log(parsed);

    return parsed;
}

function loadPlugins(path) {
    var exp,
        plugin,
        pluginPath;

    fs.readdirSync(path).forEach(function (file) {
        if (file.match(/\.js$/)) {
            pluginPath = path + '/' + file;
            console.log('require ' + pluginPath);
            plugin = require(pluginPath);

            for (exp in plugin) {
                conn.addListener(exp, plugin[exp]);
            }
        }
    });
}

var conn = net.createConnection(serverPort, host=serverHost);
conn.messageBuffer = '';

conn.sendMessage = function (command, text) {
    var formatted = formatIrcMessage(command, text);

    console.log('send ' + formatted);
    this.write(formatted);
};

conn.privmsg = function (to, message) {
    this.sendMessage('PRIVMSG', to + ' :' + message);
};

conn.addListener('connect', function () {
    this.sendMessage('PASS', serverPass);
    this.sendMessage('NICK', botNick);
    this.sendMessage('USER', botNick + ' * * ' + botNick);
});

conn.addListener('data', function (buffer) {
    var connection;

    console.log('receive ' + buffer.toString());
    this.messageBuffer += buffer.toString();

    if (this.messageBuffer.match(new RegExp(IRC_MESSAGE_END + '$'))) {
        connection = this;
        this.messageBuffer.split(IRC_MESSAGE_END).forEach(function (message) {
            var parsedMessage;
            if (!(message === '')) {
                parsedMessage = parseIrcMessage(message);
                connection.emit(parsedMessage.command, parsedMessage);
            }
        });
        this.messageBuffer = '';
    }
});

// spawn a child process and call lineCallback for each line of its stdout
conn.spawn = function (command, args, lineCallback) {
    var child = spawn(command, args),
        buffer = '',
        lines;

    child.stdout.on('data', function (data) {
        lines = (buffer + data).split('\n');
        buffer = lines.pop();
        lines.forEach(lineCallback);
    });

    return child;
};

// IRC command listeners

// welcome
conn.addListener('001', function () {
    var connection = this;

    joinChannels.forEach(function (channel) {
        connection.sendMessage('JOIN', channel);
    });
});

conn.addListener('PING', function (m) {
    this.sendMessage('PONG', m.params[0]);
});

conn.addListener('PRIVMSG', function (m) {
{'fraction_non_alphanumeric': 0.16082644628099174, 'fraction_numerical': 0.005619834710743801, 'mean_word_length': 2.5365283459964933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4838287', 'n_tokens_mistral': 1879, 'n_tokens_neox': 1821, 'n_words': 362}