<commit_before>'use strict';

var co = require('co');
var util = require('util');
var logger = require('winston');
var Table = require('cli-table2');
var api = require('../api');
var manifest = require('../manifest');
var message = require('../../../message');
var moment = require('moment');

var app = require.main.exports;
var bot = app.bot;
var config = app.config;

var lineLength = 47;

var detailBorders = {
            'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
            , 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
            , 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
            , 'right': '', 'right-mid': '', 'middle': ' | '
};

var noBorders = {
            'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
            , 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
            , 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
            , 'right': '', 'right-mid': '', 'middle': ''
};


function trials(format, activities, definitions, destinations) {

    return co(function* () {

        var activity = activities.trials;
        if(!activity) {
            return "```" + format + "\nTrials of Osiris is not currently active```";    
        };
        logger.verbose('reporting ' + activity.display.advisorTypeCategory);

        var toSend = ["```" + format];

        var titleLine;
        titleLine = "-- " + activity.display.advisorTypeCategory + " ";
        titleLine += "-".repeat(lineLength - titleLine.length);
        toSend.push(titleLine);

        // check if it's active
        var status = activity.status;

        var detailTable = new Table({
            chars: detailBorders,
            style: { 'padding-left': 0, 'padding-right': 0 },
            colWidths: [10, lineLength - 10 - 3],
            colAligns: [ 'right', 'left'],
            wordWrap: true
        });

        detailTable.push(['Status', status.active ? "Active" : "Inactive"]);
        if (status.active && status.expirationKnown) {
            detailTable.push(['Ends', moment(status.expirationDate).format('YYYY-MM-DD HH:mm') + 
                " ("+moment(status.expirationDate).fromNow()+ ")"]);
        }
        toSend.push(detailTable.toString().replace(/ +\n/g, "\n"));

        //logger.debug("rewards: ", activity.extended.winRewardDetails);
        // getDestinyInventoryItemDefinition
        // rewards
        var rank;
        var ranks = activity.extended.winRewardDetails;
        for(rank = 0; rank < ranks.length; rank++) {

            // skip anything that has 0 rewards
            var rewards = ranks[rank].rewardItemHashes;
            if(!rewards.length) continue;

            var rewardRank;
            rewardRank = "## Reward Rank " + ranks[rank].rewardRank + " ";
            rewardRank += "#".repeat(lineLength - rewardRank.length);
            toSend.push(rewardRank);  

            var rewardTable = new Table({
                chars: detailBorders,
                style: { 'padding-left': 0, 'padding-right': 0 },
                //colWidths: [10, lineLength - 10 - 3],
                colAligns: [ 'right', 'left'],
                wordWrap: true
            });

            for(var reward = 0; reward < rewards.length; reward++) {
                // lookup the reward
                // item.itemDescription
                var item = yield manifest.getDestinyInventoryItemDefinition(rewards[reward], 'en');
                rewardTable.push([item.itemTypeName, item.itemName]);
            }

            toSend.push(rewardTable.toString().replace(/ +\n/g, "\n"));
        }

        toSend.push("```");

        return toSend.join("\n");

    });
}

//
// Report on an activity with a single tier of rewards<commit_msg>advisor fix for when manifest is stale<commit_after>'use strict';

var co = require('co');
var util = require('util');
var logger = require('winston');
var Table = require('cli-table2');
var api = require('../api');
var manifest = require('../manifest');
var message = require('../../../message');
var moment = require('moment');

var app = require.main.exports;
var bot = app.bot;
var config = app.config;

var lineLength = 47;

var detailBorders = {
            'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
            , 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
            , 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
            , 'right': '', 'right-mid': '', 'middle': ' | '
};

var noBorders = {
            'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
            , 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
            , 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
            , 'right': '', 'right-mid': '', 'middle': ''
};


function trials(format, activities, definitions, destinations) {

    return co(function* () {

        var activity = activities.trials;
        if(!activity) {
            return "```" + format + "\nTrials of Osiris is not currently active```";    
        };
        logger.verbose('reporting ' + activity.display.advisorTypeCategory);

        var toSend = ["```" + format];

        var titleLine;
        titleLine = "-- " + activity.display.advisorTypeCategory + " ";
        titleLine += "-".repeat(lineLength - titleLine.length);
        toSend.push(titleLine);

        // check if it's active
        var status = activity.status;

        var detailTable = new Table({
            chars: detailBorders,
            style: { 'padding-left': 0, 'padding-right': 0 },
            colWidths: [10, lineLength - 10 - 3],
            colAligns: [ 'right', 'left'],
            wordWrap: true
        });

        detailTable.push(['Status', status.active ? "Active" : "Inactive"]);
        if (status.active && status.expirationKnown) {
            detailTable.push(['Ends', moment(status.expirationDate).format('YYYY-MM-DD HH:mm') + 
                " ("+moment(status.expirationDate).fromNow()+ ")"]);
        }
        toSend.push(detailTable.toString().replace(/ +\n/g, "\n"));

        //logger.debug("rewards: ", activity.extended.winRewardDetails);
        // getDestinyInventoryItemDefinition
        // rewards
        var rank;
        var ranks = activity.extended.winRewardDetails;
        for(rank = 0; rank < ranks.length; rank++) {

            // skip anything that has 0 rewards
            var rewards = ranks[rank].rewardItemHashes;
            if(!rewards.length) continue;

            var rewardRank;
            rewardRank = "## Reward Rank " + ranks[rank].rewardRank + " ";
            rewardRank += "#".repeat(lineLength - rewardRank.length);
            toSend.push(rewardRank);  

            var rewardTable = new Table({
                chars: detailBorders,
                style: { 'padding-left': 0, 'padding-right': 0 },
                //colWidths: [10, lineLength - 10 - 3],
                colAligns: [ 'right', 'left'],
                wordWrap: true
            });

            for(var reward = 0; reward < rewards.length; reward++) {
                // lookup the reward
                // item.itemDescription
                var item = yield manifest.getDestinyInventoryItemDefinition(rewards[reward], 'en');
                if(item) {
                    rewardTable.push([item.itemTypeName, item.itemName]);
                }
                
            }

            toSend.push(rewardTable.toString().replace(/ +\n/g, "\n"));
        }

        toSend.push("```");

        return toSend.join("\n");

    });
}

//
// Report on an activity with a single tier of rewards
{'fraction_non_alphanumeric': 0.17852929610696028, 'fraction_numerical': 0.005243151133831433, 'mean_word_length': 2.0313865713150574, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2875825', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2127, 'n_words': 478}