<commit_before>'use strict';
/*eslint camelcase:0, max-len: [1, 90, 4] */
exports.name = 'TrustCheck';
exports.version = '0.5.0';
exports.description = 'Provide reports of trust levels';
exports.configuration = {
    enabled: false
};

var discourse,
    trigger;

exports.begin = function begin(browser, c) {
    discourse = browser;
    trigger = new RegExp('@' + c.username + '\\s+trust');
};

exports.onNotify = function (type, notification, topic, post, callback) {
    if (['private_message', 'mentioned', 'replied'].indexOf(type) < 0) {
        return callback();
    }
    var isRequest = trigger.test(post.cleaned);
    if (!isRequest) {
        return callback();
    }
    discourse.getUserData(post.username, function (err, user) {
        if (err) {
            return callback();
        }
        discourse.createPost(notification.topic_id,
            notification.post_number, formatReport(user),
            function () {
                callback(true);
            });
    });
};

function formatReport(user) {
    var txt = getReportBase(user);
    txt = txt.replace('%USERNAME%', user.username);
    txt = txt.replace('%TRUST%', user.trust_level);
    txt = txt.replace('%TRUST_LOCK%', user.trust_level_locked ? 'LOCKED' :
        'Not locked');
    if (user.tl3_requirements) {
        for (var key in user.tl3_requirements) {
            txt = txt.replace('%' + key + '%', user.tl3_requirements[key]);
        }
        txt = txt.replace('%analysis%', promotionAnalysis(user));
    }
    return txt;
}

function getReportBase(user) {
    var base = '```text\n' +<commit_msg>Enchance Trust to allow TL4s to run trust query for any user<commit_after>'use strict';

var XRegExp = require('xregexp').XRegExp;

/*eslint camelcase:0, max-len: [1, 90, 4] */
exports.name = 'TrustCheck';
exports.version = '0.5.0';
exports.description = 'Provide reports of trust levels';
exports.configuration = {
    enabled: false
};

var discourse,
    trigger;

exports.begin = function begin(browser, c) {
    discourse = browser;
    trigger = new XRegExp('@' + c.username + '\\s+trust(?<args>(\\s+(\\S+))*)');
};

exports.onNotify = function (type, notification, topic, post, callback) {
    if (['private_message', 'mentioned', 'replied'].indexOf(type) < 0) {
        return callback();
    }
    var username = post.username;
    var parts = trigger.xexec(post.cleaned);
    if (!parts) {
        return callback();
    }
    if (post.trust_level >= 4 && parts.args) {
        parts.args = parts.args.trim().split(' ');
        if (parts.args.length > 0) {
            username = parts.args[0];
        }
    }
    discourse.getUserData(username, function (err, user) {
        if (err) {
            return callback();
        }
        discourse.createPost(notification.topic_id,
            notification.post_number, formatReport(user),
            function () {
                callback(true);
            });
    });
};

function formatReport(user) {
    var txt = getReportBase(user);
    txt = txt.replace('%USERNAME%', user.username);
    txt = txt.replace('%TRUST%', user.trust_level);
    txt = txt.replace('%TRUST_LOCK%', user.trust_level_locked ? 'LOCKED' :
        'Not locked');
    if (user.tl3_requirements) {
        for (var key in user.tl3_requirements) {
            txt = txt.replace('%' + key + '%', user.tl3_requirements[key]);
        }
        txt = txt.replace('%analysis%', promotionAnalysis(user));
    }
    return txt;
}

function getReportBase(user) {
    var base = '```text\n' +
{'fraction_non_alphanumeric': 0.1577152600170503, 'fraction_numerical': 0.007956805910770106, 'mean_word_length': 2.732767762460233, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2933305', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1102, 'n_words': 242}