<commit_before>var http = require('http');
var xml = require('libxmljs');

var WolframAlpha = module.exports = function(bot) {
    bot.register_command('w', this.queryWolfram);
    bot.register_command('wolfram', 'w');
};

WolframAlpha.prototype.queryWolfram = function(context, text) {
    if (text == "") {
        context.bot.send_message(context.channel, "I need something to send...", context.sender);
        return;
    }

    var url = 'https://www.wolframalpha.com/input/?i=' + encodeURIComponent(text);

    var options = {
        hostname: 'api.wolframalpha.com',
        port: 80,
        path: '/v2/query?input=' + encodeURIComponent(text) + '&primary=true&appid=' + context.bot.profile.wolframKey,
        method: 'GET',
        headers: {
            "User-Agent": "Mozilla/5.0 vbot/0.1.0"
        }
    };
    var req = http.request(options, function(res) {
        res.setEncoding('utf8');
        var body = '';
        res.on('data', function(chunk) {body += chunk;});
        res.on('end', function() {
            var doc = xml.parseXml(body), root = doc.root();

            if(root.attr('error').value() != 'false') {
                var message = root.get('//error/msg').text()
                context.bot.send_message(context.channel, "Sorry, an error occured :/", context.sender);
                console.log(message);
                return;
            }
            else {
                root.find('pod').map(function(pod) {
                    var title = pod.attr('title').value();
                    if (title === "Result") {
                        var value = pod.find('subpod').map(function(node) {return node.get('plaintext').text();});
                        context.bot.send_message(context.channel, value + ". Link: " + url, context.intent);
                    }
                });
            }
        });
    });

    req.on('error', function(e) {<commit_msg>Says when calculation can't happen<commit_after>var http = require('http');
var xml = require('libxmljs');

var WolframAlpha = module.exports = function(bot) {
    bot.register_command('w', this.queryWolfram);
    bot.register_command('wolfram', 'w');
};

WolframAlpha.prototype.queryWolfram = function(context, text) {
    if (text == "") {
        context.bot.send_message(context.channel, "I need something to send...", context.sender);
        return;
    }

    var url = 'https://www.wolframalpha.com/input/?i=' + encodeURIComponent(text);

    var options = {
        hostname: 'api.wolframalpha.com',
        port: 80,
        path: '/v2/query?input=' + encodeURIComponent(text) + '&primary=true&appid=' + context.bot.profile.wolframKey,
        method: 'GET',
        headers: {
            "User-Agent": "Mozilla/5.0 vbot/0.1.0"
        }
    };
    var req = http.request(options, function(res) {
        res.setEncoding('utf8');
        var body = '';
        res.on('data', function(chunk) {body += chunk;});
        res.on('end', function() {
            var doc = xml.parseXml(body), root = doc.root();

            if(root.attr('error').value() != 'false') {
                var message = root.get('//error/msg').text()
                context.bot.send_message(context.channel, "Sorry, an error occured :/", context.sender);
                console.log(message);
                return;
            }
            else {
                if (root.find('pod').length !== 0) {
                    root.find('pod').map(function(pod) {
                        var title = pod.attr('title').value();
                        if (title === "Result") {
                            var value = pod.find('subpod').map(function(node) {return node.get('plaintext').text();});
                            context.bot.send_message(context.channel, value + ". Link: " + url, context.intent);
                        }
                    });
                }
                else context.bot.send_message(context.channel, "Sorry, wolfram can't calculate that", context.sender);
            }
        });
    });

    req.on('error', function(e) {
{'fraction_non_alphanumeric': 0.16456945472489515, 'fraction_numerical': 0.004687885516901061, 'mean_word_length': 1.9355539464156408, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '481952', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1189, 'n_words': 213}