<commit_before>var authcommon = require('../authcommon'),
    check = require('./msgcheck').check,
    common = require('../common'),
    config = require('../config'),
    db = require('../db'),
    hooks = require('../hooks');

var RANGES = require('./state').dbCache.ranges;

function can_access_board(ident, board) {
	if (board == 'graveyard' && can_administrate(ident))
		return true;
	if (board == config.STAFF_BOARD && !can_moderate(ident))
		return false;
	if (ident.ban || ident.suspension)
		return false;
	if (under_curfew(ident, board))
		return false;
	return db.is_board(board);
}
exports.can_access_board = can_access_board;

exports.can_access_thread = function (ident, op) {
	var tags = db.tags_of(op);
	if (!tags)
		return false;
	for (var i = 0; i < tags.length; i++)
		if (can_access_board(ident, tags[i]))
			return true;
	return false;
};

function can_moderate(ident) {
	return (ident.auth === 'Admin' || ident.auth === 'Moderator');
}
exports.can_moderate = can_moderate;

function can_administrate(ident) {
	return ident.auth === 'Admin';
}
exports.can_administrate = can_administrate;

function denote_priv(info) {
	if (info.data.priv)
		info.header.push(' (priv)');
}

function dead_media_paths(paths) {
	paths.src = '../dead/src/';
	paths.thumb = '../dead/thumb/';
}

exports.augment_oneesama = function (oneeSama, opts) {
	var ident = opts.ident;
	oneeSama.ident = ident;
	if (can_moderate(ident))
		oneeSama.hook('headerName', authcommon.append_mnemonic);
	if (can_administrate(ident)) {
		oneeSama.hook('headerName', denote_priv);
		oneeSama.hook('headerName', authcommon.denote_hidden);
	}
	if (can_administrate(ident) && opts.board == 'graveyard')
		oneeSama.hook('mediaPaths', dead_media_paths);
};

exports.mod_handler = function (func) {
	return function (nums, client) {
		if (!can_moderate(client.ident))
			return false;
		var opts = nums.shift();
		if (!check({when: 'string'}, opts) || !check('id...', nums))
			return false;
		if (!(opts.when in authcommon.delayDurations))
			return false;
		var delay = authcommon.delayDurations[opts.when];
		if (!delay)
			func(nums, client);
		else
			setTimeout(func.bind(null, nums, client), delay*1000);
		return true;
	};
};

function parse_ip(ip) {
	var m = ip.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)(?:\/(\d+))?$/);
	if (!m)
		return false;
	// damn you signed int32s!
	var num = 0;
	for (var i = 4, shift = 1; i > 0; i--) {
		num += parseInt(m[i], 10) * shift;
		shift *= 256;
	}

	var info = {full: ip, num: num};
	if (m[5]) {
		var bits = parseInt(m[5], 10);
		if (bits > 0 && bits <= 32)
			info.mask = 0x100000000 - Math.pow(2, 32 - bits);
	}
	return info;
}

function parse_ranges(ranges) {
	if (!ranges)
		return [];
	ranges = ranges.map(function (o) {
		if (typeof o == 'object') {<commit_msg>Easier range masking<commit_after>var authcommon = require('../authcommon'),
    check = require('./msgcheck').check,
    common = require('../common'),
    config = require('../config'),
    db = require('../db'),
    hooks = require('../hooks');

var RANGES = require('./state').dbCache.ranges;

function can_access_board(ident, board) {
	if (board == 'graveyard' && can_administrate(ident))
		return true;
	if (board == config.STAFF_BOARD && !can_moderate(ident))
		return false;
	if (ident.ban || ident.suspension)
		return false;
	if (under_curfew(ident, board))
		return false;
	return db.is_board(board);
}
exports.can_access_board = can_access_board;

exports.can_access_thread = function (ident, op) {
	var tags = db.tags_of(op);
	if (!tags)
		return false;
	for (var i = 0; i < tags.length; i++)
		if (can_access_board(ident, tags[i]))
			return true;
	return false;
};

function can_moderate(ident) {
	return (ident.auth === 'Admin' || ident.auth === 'Moderator');
}
exports.can_moderate = can_moderate;

function can_administrate(ident) {
	return ident.auth === 'Admin';
}
exports.can_administrate = can_administrate;

function denote_priv(info) {
	if (info.data.priv)
		info.header.push(' (priv)');
}

function dead_media_paths(paths) {
	paths.src = '../dead/src/';
	paths.thumb = '../dead/thumb/';
}

exports.augment_oneesama = function (oneeSama, opts) {
	var ident = opts.ident;
	oneeSama.ident = ident;
	if (can_moderate(ident))
		oneeSama.hook('headerName', authcommon.append_mnemonic);
	if (can_administrate(ident)) {
		oneeSama.hook('headerName', denote_priv);
		oneeSama.hook('headerName', authcommon.denote_hidden);
	}
	if (can_administrate(ident) && opts.board == 'graveyard')
		oneeSama.hook('mediaPaths', dead_media_paths);
};

exports.mod_handler = function (func) {
	return function (nums, client) {
		if (!can_moderate(client.ident))
			return false;
		var opts = nums.shift();
		if (!check({when: 'string'}, opts) || !check('id...', nums))
			return false;
		if (!(opts.when in authcommon.delayDurations))
			return false;
		var delay = authcommon.delayDurations[opts.when];
		if (!delay)
			func(nums, client);
		else
			setTimeout(func.bind(null, nums, client), delay*1000);
		return true;
	};
};

function parse_ip(ip) {
	var m = ip.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)(?:\/(\d+))?$/);
	if (!m)
		return false;
	// damn you signed int32s!
	var num = 0;
	for (var i = 4, shift = 1; i > 0; i--) {
		num += parseInt(m[i], 10) * shift;
		shift *= 256;
	}

	var info = {full: ip, num: num};
	if (m[5]) {
		var bits = parseInt(m[5], 10);
		if (bits > 0 && bits <= 32) {
			info.mask = 0x100000000 - Math.pow(2, 32 - bits);
			info.num &= info.mask;
		}
	}
	return info;
}

function parse_ranges(ranges) {
	if (!ranges)
		return [];
	ranges = ranges.map(function (o) {
		if (typeof o == 'object') {
{'fraction_non_alphanumeric': 0.18365161520613957, 'fraction_numerical': 0.012850258789933964, 'mean_word_length': 4.026008968609865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4351884', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2072, 'n_words': 468}