<commit_before>/*jslint todo: true */
"use strict";

var // GBot = require("../../../lib/bot/GBot.js"),
    //KBase = require("../../bot/KBase"),
    Utils = require("../../../lib/utils/Utils"),
    //AppConfig = require("../../../config/AppConfig"),
    HttpWrap = require("../../../lib/utils/HttpWrap");

var TextLib = require("../../../lib/utils/TextLib");



//var newline = '\n';

//var clog = require('../../utils/clog.js');

// clog("clog from thanks");

// function clog(msg, obj) {
//     Utils.clog("BotCommands>", msg, obj);
// }

// function tlog(msg, obj) {
//     Utils.warn("BotCommands>", msg, obj);
// }



var commands = {

    thanks: function (input, bot) {
        Utils.hasProperty(input, "message", "thanks expects an object");

        var mentions, output, fromUser, toUser, toUserMessage;
        mentions = input.message.model.mentions;
        if (mentions && mentions.length === 0 ) { return null; } // just 'thanks' in a message

        fromUser = input.message.model.fromUser.username.toLowerCase();
        var options = {
            method: 'POST',
            input: input,
            bot: bot
        };

        var namesList = mentions.map(function (m) {
            toUser = m.screenName.toLowerCase();
            if (toUser != fromUser) {
              var apiPath = "/api/users/give-brownie-points?receiver=" + toUser + "&giver=" + fromUser;
              HttpWrap.callApi(apiPath, options, commands.showInfo);
              return toUser;
            } else {
              return null;
            }
        });

        if ( namesList[0] != null ) {
          toUserMessage = namesList.join(" and @");
          output = "> " + fromUser + " sends brownie points to @" + toUserMessage;
          output += " :sparkles: :thumbsup: :sparkles: ";
          return output;
        } else {
          output = "> sorry " + fromUser + ", you can't send brownie points to yourself!";
          output += " :sparkles: :sparkles: ";
          return output;
      }
    },

    about: function(input, bot) {
        // var mentioned = InputWrap.mentioned(input);
        var mentions, them, name;

        mentions = input.message.model.mentions;
        them = mentions[0];
        if (!them) {
            return "you need to ask about @someone!";
        }
        name = them.screenName.toLowerCase();
        var options = {
            method: 'GET',
            input: input,
            bot: bot
        }

        var apiPath = '/api/users/about?username=' + name;
        HttpWrap.callApi(apiPath, options, commands.showInfo);
    },

    // called back from apiCall
    // blob:
    //      response
    //      bot
    //      input


    showInfo: function(blob) {
        //Utils.clog('thanks>', "showInfo>", blob);

        // in case we want to filter the message
        var cleanMessage = function(message) {
            //return message;
            if (message.match(/^FCC: no user/)) {
                message = "hmm, can't find that user on the beta site. wait til we release new version!"
            }
            message = "> :warning: " + message;
            return message;
        }

        if (blob.response.error) {
            var message = cleanMessage(blob.response.error.message);
            //message += Utils.betaFooter();
            Utils.warn("WARN @thanks>", blob.response.error.message, blob.response.error);
            //blob.bot.say(message, blob.input.message.room);
            return false;
        }

        var username = blob.response.about.username;
        var about = blob.response.about;
        var bio = blob.response.about.bio || "no bio set";

        var uri = "http://www.freecodecamp.com/" + username;
        var str = "> :star: " + about.browniePoints + " | @" + username + " | ";
            str += TextLib.mdLink(uri, uri);

//        var XXstr = `
//![${username}](https://avatars2.githubusercontent.com/${username}?&s=32) | [${username}](http://www.freecodecamp.com/${username})
//        -------------                       | -------------
//        :star: ${about.browniePoints}       | ${bio}
//
//        `;
        //Utils.clog("thanks callback>", str);
        blob.bot.say(str, blob.input.message.room);
    }

};

module.exports = commands;
<commit_msg>added wiki prompt to thanks msg closes #79<commit_after>/*jslint todo: true */
"use strict";

var // GBot = require("../../../lib/bot/GBot.js"),
    //KBase = require("../../bot/KBase"),
    Utils = require("../../../lib/utils/Utils"),
    //AppConfig = require("../../../config/AppConfig"),
    HttpWrap = require("../../../lib/utils/HttpWrap");

var TextLib = require("../../../lib/utils/TextLib");



//var newline = '\n';

//var clog = require('../../utils/clog.js');

// clog("clog from thanks");

// function clog(msg, obj) {
//     Utils.clog("BotCommands>", msg, obj);
// }

// function tlog(msg, obj) {
//     Utils.warn("BotCommands>", msg, obj);
// }



var commands = {

    messages: {
        wikiHint: function(fromUser) {
            var wikiUrl = "(https://github.com/freecodecamp/freecodecamp/wiki/wiki-style-guide)";
            var msg = "\n> hey @" + fromUser + " if you found this info helpful :point_right: **[consider adding a wiki article!]" + wikiUrl + "**";
            return msg;
        }
    },

    thanks: function (input, bot) {
        Utils.hasProperty(input, "message", "thanks expects an object");

        var mentions, output, fromUser, toUser, toUserMessage;
        mentions = input.message.model.mentions;
        if (mentions && mentions.length === 0 ) { return null; } // just 'thanks' in a message

        fromUser = input.message.model.fromUser.username.toLowerCase();
        var options = {
            method: 'POST',
            input: input,
            bot: bot
        };

        var namesList = mentions.map(function (m) {
            toUser = m.screenName.toLowerCase();
            if (toUser != fromUser) {
              var apiPath = "/api/users/give-brownie-points?receiver=" + toUser + "&giver=" + fromUser;
              HttpWrap.callApi(apiPath, options, commands.showInfo);
              return toUser;
            } else {
              return null;
            }
        });

        if ( namesList[0] != null ) {
          toUserMessage = namesList.join(" and @");
          output = "> " + fromUser + " sends brownie points to @" + toUserMessage;
          output += " :sparkles: :thumbsup: :sparkles: ";
          output += this.messages.wikiHint(fromUser);
          return output;
        } else {
          output = "> sorry " + fromUser + ", you can't send brownie points to yourself!";
          output += " :sparkles: :sparkles: ";
          return output;
      }
    },

    about: function(input, bot) {
        // var mentioned = InputWrap.mentioned(input);
        var mentions, them, name;

        mentions = input.message.model.mentions;
        them = mentions[0];
        if (!them) {
            return "you need to ask about @someone!";
        }
        name = them.screenName.toLowerCase();
        var options = {
            method: 'GET',
            input: input,
            bot: bot
        }

        var apiPath = '/api/users/about?username=' + name;
        HttpWrap.callApi(apiPath, options, commands.showInfo);
    },

    // called back from apiCall
    // blob:
    //      response
    //      bot
    //      input


    showInfo: function(blob) {
        //Utils.clog('thanks>', "showInfo>", blob);

        // in case we want to filter the message
        var cleanMessage = function(message) {
            //return message;
            if (message.match(/^FCC: no user/)) {
                message = "hmm, can't find that user on the beta site. wait til we release new version!"
            }
            message = "> :warning: " + message;
            return message;
        }

        if (blob.response.error) {
            var message = cleanMessage(blob.response.error.message);
            //message += Utils.betaFooter();
            Utils.warn("WARN @thanks>", blob.response.error.message, blob.response.error);
            //blob.bot.say(message, blob.input.message.room);
            return false;
        }

        var username = blob.response.about.username;
        var about = blob.response.about;
        var bio = blob.response.about.bio || "no bio set";

        var uri = "http://www.freecodecamp.com/" + username;
        var str = "> :star: " + about.browniePoints + " | @" + username + " | ";
            str += TextLib.mdLink(uri, uri);

//        var XXstr = `
//![${username}](https://avatars2.githubusercontent.com/${username}?&s=32) | [${username}](http://www.freecodecamp.com/${username})
//        -------------                       | -------------
//        :star: ${about.browniePoints}       | ${bio}
//
//        `;
        //Utils.clog("thanks callback>", str);
        blob.bot.say(str, blob.input.message.room);
    }

};

module.exports = commands;

{'fraction_non_alphanumeric': 0.16597880646960403, 'fraction_numerical': 0.0015616285554935863, 'mean_word_length': 1.7853370611991302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 3, 'lorem ipsum': 0, 'www.': 4, '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': '4505986', 'n_tokens_mistral': 2678, 'n_tokens_neox': 2560, 'n_words': 601}