<commit_before>var parseDiceSpec = function (specString) {
    var rawSpec = specString.valMatch(/^([0-9]*)d(%|[0-9]*)$/i, 3);
    if (rawSpec !== false) {
        if (rawSpec[2] === "%") {
            rawSpec[2] = 100;
        }
        return {
            "count": parseInt(rawSpec[1] || 1),
            "sides": parseInt(rawSpec[2] || 6)
        };
    } else {
        return false;
    }
};

var normalizeDiceSpec = function (specString) {
    var diceSpec = parseDiceSpec(specString);
    return (diceSpec["count"] > 1 ? diceSpec["count"] : "") + "d" + (diceSpec["sides"] === 100 ? "%" : diceSpec["sides"]);
};

var dice = function(dbot) {
    var commands = {
        '~roll': function (data, params) {
            var rolls = [];

            if (params.length === 1) {
                params.push("d6");
            }

            for (var i = 1; i < params.length; i++) {
                var diceSpec = parseDiceSpec(params[i]);
                if (diceSpec === false) {
                    rolls.push([params[i], false]);
                } else {
                    rolls.push([normalizeDiceSpec(params[i]), []]);
                    for (var j = 0; j < diceSpec["count"] ; j++) {
                        rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"]));
                    }<commit_msg>And there's the modifiers. Beautiful.<commit_after>var parseDiceSpec = function (specString) {
    var rawSpec = specString.valMatch(/^([0-9]*)d(%|[0-9]*)(|[+-][0-9]+)$/i, 4);
    if (rawSpec !== false) {
        if (rawSpec[2] === "%") {
            rawSpec[2] = 100;
        }
        return {
            "count": parseInt(rawSpec[1] || 1),
            "sides": parseInt(rawSpec[2] || 6),
            "modifier": parseInt(rawSpec[3] || 0)
        };
    } else {
        return false;
    }
};

var normalizeDiceSpec = function (specString) {
    var diceSpec = parseDiceSpec(specString);

    if (diceSpec["count"] > 1) {
        var count = diceSpec["count"];
    } else {
        var count = "";
    }

    if (diceSpec["sides"] === 100) {
        var sides = "%";
    } else {
        var sides = diceSpec["sides"];
    }

    if (diceSpec["modifier"] > 0) {
        var modifier = "+" + diceSpec["modifier"];
    } else if (diceSpec["modifier"] < 0) {
        var modifier = diceSpec["modifier"];
    } else {
        var modifier = "";
    }

    return (count + "d" + sides + modifier);
};

var dice = function(dbot) {
    var commands = {
        '~roll': function (data, params) {
            var rolls = [];

            if (params.length === 1) {
                params.push("d6");
            }

            for (var i = 1; i < params.length; i++) {
                var diceSpec = parseDiceSpec(params[i]);
                if (diceSpec === false) {
                    rolls.push([params[i], false]);
                } else {
                    rolls.push([normalizeDiceSpec(params[i]), []]);
                    for (var j = 0; j < diceSpec["count"] ; j++) {
                        rolls[rolls.length-1][1].push(Math.ceil(Math.random() * diceSpec["sides"]) + diceSpec["modifier"]);
                    }
{'fraction_non_alphanumeric': 0.1803747221340108, 'fraction_numerical': 0.01714830104795173, 'mean_word_length': 1.7415143603133159, 'pattern_counts': {'":': 5, '<': 8, '<?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': '179285', 'n_tokens_mistral': 1040, 'n_tokens_neox': 987, 'n_words': 201}