<commit_before>var util = require("util");
var _ = require("lodash");
var Helper = require("../helper");
var log = require("../log");

module.exports = Chan;

Chan.Type = {
	CHANNEL: "channel",
	LOBBY: "lobby",
	QUERY: "query"
};

var MessageArray = function(chan){
    Array.call(this);
    this.chan = chan;
    this.log = Helper.HOME + "/logs/" + this.chan.user 
        + "/" + this.chan.network + "/" + this.chan.channel + ".log";
    var that = this;
    Helper.countLines(this.log, function(err, count){
        that.count = err ? 0 : count;
    });
};
util.inherits(MessageArray, Array);

MessageArray.prototype.push = function(message) {
    var config = Helper.getConfig();
    if (config.log === true) {
        if (this.length > 50) this.splice(50);
    }
    Array.prototype.push.call(this, message);
    this.count++;
};

MessageArray.prototype.fetch = function(from, to, callback) {
    var messages = [];
    if (from < this.length) messages = messages.concat(this.slice(from));
    if (to <= this.length) callback(null, messages.slice(0, to));
    else if (this.log) {
        var linesFrom = from + messages.length;
        Helper.getLines(this.log, linesFrom, to, function(err, lines){
            callback(null, messages.concat(lines.map(log.parse))); 
        });
    }
    else callback(null, messages);
};

var id = 0;

function Chan(attr) {
	_.merge(this, _.extend({
		id: id++,
		name: "",
		topic: "",
		type: Chan.Type.CHANNEL,
		unread: 0,
		users: []
	}, attr));
	this.messages = new MessageArray(this);
}

Chan.prototype.sortUsers = function() {
	this.users = _.sortBy(
		this.users,
		function(u) { return u.name.toLowerCase(); }
	);
	var modes = [
		"~",
		"!",<commit_msg>Revert "Elemental-IRCd compat: modeflag ! support"<commit_after>var util = require("util");
var _ = require("lodash");
var Helper = require("../helper");
var log = require("../log");

module.exports = Chan;

Chan.Type = {
	CHANNEL: "channel",
	LOBBY: "lobby",
	QUERY: "query"
};

var MessageArray = function(chan){
    Array.call(this);
    this.chan = chan;
    this.log = Helper.HOME + "/logs/" + this.chan.user 
        + "/" + this.chan.network + "/" + this.chan.channel + ".log";
    var that = this;
    Helper.countLines(this.log, function(err, count){
        that.count = err ? 0 : count;
    });
};
util.inherits(MessageArray, Array);

MessageArray.prototype.push = function(message) {
    var config = Helper.getConfig();
    if (config.log === true) {
        if (this.length > 50) this.splice(50);
    }
    Array.prototype.push.call(this, message);
    this.count++;
};

MessageArray.prototype.fetch = function(from, to, callback) {
    var messages = [];
    if (from < this.length) messages = messages.concat(this.slice(from));
    if (to <= this.length) callback(null, messages.slice(0, to));
    else if (this.log) {
        var linesFrom = from + messages.length;
        Helper.getLines(this.log, linesFrom, to, function(err, lines){
            callback(null, messages.concat(lines.map(log.parse))); 
        });
    }
    else callback(null, messages);
};

var id = 0;

function Chan(attr) {
	_.merge(this, _.extend({
		id: id++,
		name: "",
		topic: "",
		type: Chan.Type.CHANNEL,
		unread: 0,
		users: []
	}, attr));
	this.messages = new MessageArray(this);
}

Chan.prototype.sortUsers = function() {
	this.users = _.sortBy(
		this.users,
		function(u) { return u.name.toLowerCase(); }
	);
	var modes = [
		"~",
		"&",
{'fraction_non_alphanumeric': 0.18131708732230925, 'fraction_numerical': 0.004641717435451117, 'mean_word_length': 3.080473372781065, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '2597024', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1172, 'n_words': 252}