<commit_before>/**
 * Simple WA calc
 */

/* jslint node: true */
/* global BOT_DIR, LIBS_DIR, MODULES_DIR */
'use strict';

/* ------------------------------ Includes && Options ----------------- */
var request = require('request');

/* ------------------------------ WolframAlpha ------------------------ */

function WolframAlpha() {
	this.solution = />Solution:<[\s\S]*?alt\s*=\s*\"([^\""]*)\"/;
	this.other = /stringified"\s*:\s*"([^"\r\n]*)/g;
	this.get_other = /stringified"\s*:\s*"/g;
}

WolframAlpha.prototype.search = function(query, callback) {
	var result = {
		url: 'http://www.wolframalpha.com/input/?i=' + encodeURIComponent(query)
	};
	var WA = this;
	request(result.url, function(error, response, body) {
		if (error || response.statusCode !== 200) {
			callback.call(WA, result);
			return;
		}

		var match = body.match(WA.solution);

		if (match) {
			result.data = match[1].replace(/\\\//, '/');
		} else {
			match = body.match(WA.other);
			if (!match || !match[1]) {
				result.data = null;
			} else {
				result.data = match[1].replace(WA.get_other, '').replace(/\\n/g, ' ').replace(/\\\//, '/');
			}
		}

		callback.call(WA, result);
	});
};

/* ------------------------------ module ---------------------------- */

exports.init = function(bot, dispatcher, calc) {
	var wa = new WolframAlpha();

	this.addCommand('calc', function(source, argv) {
		if (!argv[0]) {
			source.mention('please tell me what to calculate. beep boop.');
			return;
		}

		source.action('casts the magic of math and ...');

		wa.search(argv.join(' '), function(result) {
			source.mention(result.data ? 'the answer to your equation is: ' + result.data.replace(/\\'/g, '\'') : 'i don\'t know the answer...');
		});
	});
};<commit_msg>fix calc command weird bug<commit_after>/**
 * Simple WA calc
 */

/* jslint node: true */
/* global BOT_DIR, LIBS_DIR, MODULES_DIR */
'use strict';

/* ------------------------------ Includes && Options ----------------- */
var request = require('request');

/* ------------------------------ WolframAlpha ------------------------ */

function WolframAlpha() {
	this.solution = />Solution:<[\s\S]*?alt\s*=\s*\"([^\""]*)\"/;
	this.other = /stringified"\s*:\s*"([^"\r\n]*)/g;
	this.get_other = /stringified"\s*:\s*"/g;
}

WolframAlpha.prototype.search = function(query, callback) {
	var result = {
		url: 'http://www.wolframalpha.com/input/?i=' + encodeURIComponent(query)
	};
	var WA = this;
	request(result.url, function(error, response, body) {
		if (error || response.statusCode !== 200) {
			callback.call(WA, result);
			return;
		}

		var match = body.match(WA.solution);

		if (match) {
			result.data = match[1].replace(/\\\//, '/');
		} else {
			match = body.match(WA.other);
			if (!match || !match[1]) {
				result.data = null;
			} else {
				result.data = match[1].replace(WA.get_other, '').replace(/\\n/g, ' ').replace(/\\\//, '/');
			}
		}

		callback.call(WA, result);
	});
};

/* ------------------------------ module ---------------------------- */

exports.init = function(bot, dispatcher, calc) {
	var wa = new WolframAlpha();

	this.addCommand('calc', function(source, argv, text) {
		if (!argv[0]) {
			source.mention('please tell me what to calculate. beep boop.');
			return;
		}

		source.action('casts the magic of math and ...');

		wa.search(text.replace('calc ', ''), function(result) {
			source.mention(result.data ? 'the answer to your equation is: ' + result.data.replace(/\\'/g, '\'') : 'i don\'t know the answer...');
		});
	});
};
{'fraction_non_alphanumeric': 0.29492298916143755, 'fraction_numerical': 0.003993154592127781, 'mean_word_length': 2.2502316960148288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6387914', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1178, 'n_words': 235}