<commit_before>var _ = require('lodash');
var DuplexStream = require('stream').Duplex;

module.exports = IrcChannel;


function IrcChannel(irc_client, channel_name, key) {
    var that = this;

    this.irc_client = irc_client;
    this.name = channel_name;

    // TODO: Proxy channel related events from irc_bot to this instance

    this.say = _.partial(irc_client.say.bind(irc_client), channel_name);
    this.notice = _.partial(irc_client.notice.bind(irc_client), channel_name);
    // this.action = _.partial(irc_client.action.bind(irc_client), channel_name);
    this.part = _.partial(irc_client.part.bind(irc_client), channel_name);
    this.join = _.partial(irc_client.join.bind(irc_client), channel_name);
    this.mode = _.partial(irc_client.mode.bind(irc_client), channel_name);
    this.banlist = _.partial(irc_client.banlist.bind(irc_client), channel_name);
    this.ban = _.partial(irc_client.ban.bind(irc_client), channel_name);
    this.unban = _.partial(irc_client.unban.bind(irc_client), channel_name);


    that.users = [];
    irc_client.on('userlist', function(event) {
        if (event.channel.toLowerCase() === that.name.toLowerCase()) {
            that.users = event.users;
        }
    });
    irc_client.on('join', function(event) {
        if (event.channel === that.name) {
            that.users.push(event);
        }
    });
    irc_client.on('part', function(event) {
        if (event.channel === that.name) {
            that.users = _.filter(that.users, function(o) {
                return o.nick.toLowerCase() !== event.nick.toLowerCase();
            });
        }
    });
    irc_client.on('kick', function(event) {
        if (event.channel === that.name) {
            that.users = _.filter(that.users, function(o) {
                return o.nick.toLowerCase() !== event.kicked.toLowerCase();
            });
        }
    });
    irc_client.on('quit', function(event) {
        that.users = _.filter(that.users, function(o) {
            return o.nick.toLowerCase() !== event.nick.toLowerCase();
        });
    });
    irc_client.on('nick', function(event) {
        _.find(that.users, function(o) {
            if(o.nick.toLowerCase() === event.nick.toLowerCase()) {
                o.nick = event.new_nick;
                return true;
            }
        });
    });
    irc_client.on('mode', function(event) {
        if (event.target === that.name) {
            // There can be multiple modes set at once, loop through
            _.each(event.modes, function(modes) {
                // Is it a channel mode ?
                if(modes.param === null) {
                    // TODO : manage channel mode changes
                } else { // It's a user mode
                    // Find the user affected
                    _.find(that.users, function(user) {
                        if(user.nick.toLowerCase() === modes.param.toLowerCase()) {
                            _.each(modes, function(mode) {
                                if(mode.substring(0,1) === '+') {
                                    if(user.modes === undefined) {
                                        user.modes = [];
                                    }
                                    user.modes.push(mode.substring(1,2));
                                } else if (mode.substring(0,1) === '-') {
                                    _.pull(user.modes, mode.substring(1,2));
                                }
                            });<commit_msg>Style tweak<commit_after>var _ = require('lodash');
var DuplexStream = require('stream').Duplex;

module.exports = IrcChannel;


function IrcChannel(irc_client, channel_name, key) {
    var that = this;

    this.irc_client = irc_client;
    this.name = channel_name;

    // TODO: Proxy channel related events from irc_bot to this instance

    this.say = _.partial(irc_client.say.bind(irc_client), channel_name);
    this.notice = _.partial(irc_client.notice.bind(irc_client), channel_name);
    // this.action = _.partial(irc_client.action.bind(irc_client), channel_name);
    this.part = _.partial(irc_client.part.bind(irc_client), channel_name);
    this.join = _.partial(irc_client.join.bind(irc_client), channel_name);
    this.mode = _.partial(irc_client.mode.bind(irc_client), channel_name);
    this.banlist = _.partial(irc_client.banlist.bind(irc_client), channel_name);
    this.ban = _.partial(irc_client.ban.bind(irc_client), channel_name);
    this.unban = _.partial(irc_client.unban.bind(irc_client), channel_name);


    that.users = [];
    irc_client.on('userlist', function(event) {
        if (event.channel.toLowerCase() === that.name.toLowerCase()) {
            that.users = event.users;
        }
    });
    irc_client.on('join', function(event) {
        if (event.channel === that.name) {
            that.users.push(event);
        }
    });
    irc_client.on('part', function(event) {
        if (event.channel === that.name) {
            that.users = _.filter(that.users, function(o) {
                return o.nick.toLowerCase() !== event.nick.toLowerCase();
            });
        }
    });
    irc_client.on('kick', function(event) {
        if (event.channel === that.name) {
            that.users = _.filter(that.users, function(o) {
                return o.nick.toLowerCase() !== event.kicked.toLowerCase();
            });
        }
    });
    irc_client.on('quit', function(event) {
        that.users = _.filter(that.users, function(o) {
            return o.nick.toLowerCase() !== event.nick.toLowerCase();
        });
    });
    irc_client.on('nick', function(event) {
        _.find(that.users, function(o) {
            if(o.nick.toLowerCase() === event.nick.toLowerCase()) {
                o.nick = event.new_nick;
                return true;
            }
        });
    });
    irc_client.on('mode', function(event) {
        if (event.target === that.name) {
            // There can be multiple modes set at once, loop through
            _.each(event.modes, function(modes) {
                // Is it a channel mode ?
                if (modes.param === null) {
                    // TODO : manage channel mode changes
                } else { // It's a user mode
                    // Find the user affected
                    _.find(that.users, function(user) {
                        if (user.nick.toLowerCase() === modes.param.toLowerCase()) {
                            _.each(modes, function(mode) {
                                if (mode.substring(0,1) === '+') {
                                    if (user.modes === undefined) {
                                        user.modes = [];
                                    }
                                    user.modes.push(mode.substring(1,2));
                                } else if (mode.substring(0,1) === '-') {
                                    _.pull(user.modes, mode.substring(1,2));
                                }
                            });
{'fraction_non_alphanumeric': 0.14216107767268557, 'fraction_numerical': 0.002292920607623961, 'mean_word_length': 1.739010989010989, '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': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1403362', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1963, 'n_words': 331}