<commit_before>// This is for common functions defined in many bots at once
var Sandbox = require("./lib/sandbox");
var FeelingLucky = require("./lib/feelinglucky");

function parse_regex_literal (text) {
	var regexparsed = text.match(/s\/((?:[^\\\/]|\\.)*)\/((?:[^\\\/]|\\.)*)\/([gi]*)$/);
	if (!regexparsed) {
		throw new SyntaxError("Syntax is `s/expression/replacetext/gi`.");
	}

	var regex = new RegExp(regexparsed[1], regexparsed[3]);
	return [regex, regexparsed[2].replace(/\\\//g, '/')];
}


var Shared = module.exports = {
	
	google: function(context, text) {
		FeelingLucky(text, function(data) {
			if (data) {
				context.channel.send_reply (context.intent, 
					"\x02"+data.title+"\x0F \x032<"+data.url+">\x0F", {color: true});
			} else {
				context.channel.send_reply (context.sender, "No search results found.");
			}
		});
	},
	
	
	execute_js: function(context, text, command, code) {
		var engine, person = context.sender;
	
		/* This should be temporary. */
		if (!context.priv) {
			if (command === "v8>" && context.channel.userlist["v8bot"]) {
				return;
			}
			if (command === "js>" && context.channel.userlist["gbot2"]) {
				return;
			}
		}
	
		switch (command) {
		case "|>": /* Multi-line input */
			person.js = person.js || {timeout: null, code: []};
			/* Clear input buffer after a minute */
			clearTimeout (person.js.timeout);
			person.js.timeout = setTimeout (function() {
				person.js.code.length = 0;
				context.channel.send_reply (context.sender, "Your `|>` line input has been cleared. (1 minute)");
			}, 1000 * 60);
			person.js.code.push (code);
			return;
		case "h>":
		case "hs>":
			engine = Sandbox.Haskell; break;
		case ">>>":
		case "v>":
		case "v8>":
			engine = Sandbox.V8; break;
		default:
			engine = Sandbox.SpiderMonkey; break;
		}

		if (person.js && person.js.code.length) {
			code = person.js.code.join("\n") + "\n" + code;
			person.js.code.length = 0;
			clearTimeout (person.js.timeout);
		}

		this.sandbox.run(engine, 2000, code, function(result) {
			var reply;

			try {
				/* If theres an error, show that.
				   If not, show the type along with the result */
				if (result.error !== null) {
					reply = result.error;
				} else {
					if (result.data.type !== "undefined") {
						reply = (result.data.obvioustype ? "" :
							"("+result.data.type+") ") + result.result;<commit_msg>Increase sandbox timeout to 3 seconds.<commit_after>// This is for common functions defined in many bots at once
var Sandbox = require("./lib/sandbox");
var FeelingLucky = require("./lib/feelinglucky");

function parse_regex_literal (text) {
	var regexparsed = text.match(/s\/((?:[^\\\/]|\\.)*)\/((?:[^\\\/]|\\.)*)\/([gi]*)$/);
	if (!regexparsed) {
		throw new SyntaxError("Syntax is `s/expression/replacetext/gi`.");
	}

	var regex = new RegExp(regexparsed[1], regexparsed[3]);
	return [regex, regexparsed[2].replace(/\\\//g, '/')];
}


var Shared = module.exports = {
	
	google: function(context, text) {
		FeelingLucky(text, function(data) {
			if (data) {
				context.channel.send_reply (context.intent, 
					"\x02"+data.title+"\x0F \x032<"+data.url+">\x0F", {color: true});
			} else {
				context.channel.send_reply (context.sender, "No search results found.");
			}
		});
	},
	
	
	execute_js: function(context, text, command, code) {
		var engine, person = context.sender;
	
		/* This should be temporary. */
		if (!context.priv) {
			if (command === "v8>" && context.channel.userlist["v8bot"]) {
				return;
			}
			if (command === "js>" && context.channel.userlist["gbot2"]) {
				return;
			}
		}
	
		switch (command) {
		case "|>": /* Multi-line input */
			person.js = person.js || {timeout: null, code: []};
			/* Clear input buffer after a minute */
			clearTimeout (person.js.timeout);
			person.js.timeout = setTimeout (function() {
				person.js.code.length = 0;
				context.channel.send_reply (context.sender, "Your `|>` line input has been cleared. (1 minute)");
			}, 1000 * 60);
			person.js.code.push (code);
			return;
		case "h>":
		case "hs>":
			engine = Sandbox.Haskell; break;
		case ">>>":
		case "v>":
		case "v8>":
			engine = Sandbox.V8; break;
		default:
			engine = Sandbox.SpiderMonkey; break;
		}

		if (person.js && person.js.code.length) {
			code = person.js.code.join("\n") + "\n" + code;
			person.js.code.length = 0;
			clearTimeout (person.js.timeout);
		}

		this.sandbox.run(engine, 3000, code, function(result) {
			var reply;

			try {
				/* If theres an error, show that.
				   If not, show the type along with the result */
				if (result.error !== null) {
					reply = result.error;
				} else {
					if (result.data.type !== "undefined") {
						reply = (result.data.obvioustype ? "" :
							"("+result.data.type+") ") + result.result;
{'fraction_non_alphanumeric': 0.19284963196635121, 'fraction_numerical': 0.011987381703470032, 'mean_word_length': 3.03392705682782, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 27, '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': '6973627', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1666, 'n_words': 384}