<commit_before>// -*- Mode: JavaScript; tab-width: 4 -*- vim:tabstop=4 syntax=javascript:
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*global aucgbot: false, ctof: false, calc: false, encodeUTF8: false, ftoc: false, module: false, randint: false, run: false, writeln: false */

if (!run("calc.js"))
	throw new Error("Could not load calc functions from calc.js");

module.version = "2.8 (10 Sep 2013)";
module.prefs = {
	abuse: {
		log: true, // when triggered with =
		warn: true // warn user sending message
	},
	error: {
		log: true,
		sendError: true,
		apologise: false,
		apologymsg: "Sorry, I encountered an error while trying to evaluate your expression."
	},
	easterEggs: true, // toggle Easter eggs :-)
	userfriendly: false,
	actDice: true // output <x>d<y> as /me rolls a d<y> x times: a, b, c; total: d
};
module.abuse = /load|run|java|ecma|op|doc|cli|(?:qui|exi|aler|prin|insul|impor|scrip)t|def|raw|throw|win|nan|open|con|p(?:ro|atch|lug|lay)|inf|my|for|(?:fals|minimi[sz]|dat|los|whil|writ|tru|typ)e|read|this|js|sys|scr|(?:de|loca|unti|rctr|eva)l|glob|[\[{'"}\]]/;
module.list = "Functions [<x>()]: acos, asin, atan, atan2, cos, sin, tan, exp, ln, pow, sqrt, abs, ceil, max, min, floor, round, random, randint, fact, mean, dice, ftoc, ctof. Constants: e, pi, phi, c. Operators: %, ^, **. Other topics: decimal, trig.";

module["cmd_="] = module.cmd_calc = module.cmd_math = function cmd_calc(dest, msg, nick, ident, host, conn, relay) {
	msg = msg.replace(/(?:\/\/|@).*$/, "").toLowerCase();
	if (msg.match(this.abuse)) {
		if (this.prefs.abuse.warn && !relay)
			conn.send("NOTICE", nick, ":Whoa! Careful dude!");
		writeln("[WARNING] Abuse detected! ^^^^^");
		if (this.prefs.abuse.log)
			aucgbot.log(conn, "CALC ABUSE", nick + (dest != nick ? " in " + dest : ""), msg);
		return true;
	}
	try {
		var s;
		if (/^(\d*)d(\d+)$/.test(msg))
			conn.msg(dest, this.cmdDice(RegExp.$2, RegExp.$1));
		else if ((s = this.parseMsg(msg)))
			conn.reply(dest, nick, s);
	} catch (ex) {
		writeln("[ERROR] ", ex);
		if (this.prefs.error.log)
			aucgbot.log(conn, "CALC ERROR", nick + (dest != nick ? " in " + dest : ""), msg, ex);
		if (this.prefs.error.apologise)
			conn.reply(dest, nick, this.prefs.error.apologymsg);
		if (this.prefs.error.sendError)
			conn.reply(dest, nick, ex);
	}
	return true;
};
module.cmd_base = function cmd_base(dest, msg, nick, ident, host, conn, relay) {
	var args = msg.split(" ");
	if (args.length < 2 || args.length > 3)
		conn.reply(dest, nick, "Invalid usage. Usage: base <num> <fromBase> [<toBase>]");
	else
		conn.reply(dest, nick, parseInt(args[0], args[1]).toString(parseInt(args[2]) || 10));
	return true;
};
module.cmd_qe = function cmd_quadraticEqn(dest, msg, nick, ident, host, conn, relay) {
	var a, b, c, _2a, pron, resInSqrt, resSqrt, res = [];
	if (!/^(?:([+\-]?\d*(?:\.\d*)?) ?\*? ?)?([A-Za-z]) ?(?:\*\*|\^) ?2 ?(?:([+\-] ?\d*(?:\.\d*)?) ?\*? ?\2)? ?([+\-] ?\d*(?:\.\d*)?)? ?= ?([+\-]?\d*(?:\.\d*)?)$/.test(msg)) {
		// not a quadratic equation, bail
		conn.reply(dest, nick, "qe: Evaluates the value of the pronumeral in a quadratic equation in general form i.e. ax**2 + bx + c = 0");
		return true;
	}<commit_msg>[calcbot] add base10 command<commit_after>// -*- Mode: JavaScript; tab-width: 4 -*- vim:tabstop=4 syntax=javascript:
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*global aucgbot: false, ctof: false, calc: false, encodeUTF8: false, ftoc: false, module: false, randint: false, run: false, writeln: false */

if (!run("calc.js"))
	throw new Error("Could not load calc functions from calc.js");

module.version = "2.9 (11 Sep 2013)";
module.prefs = {
	abuse: {
		log: true, // when triggered with =
		warn: true // warn user sending message
	},
	error: {
		log: true,
		sendError: true,
		apologise: false,
		apologymsg: "Sorry, I encountered an error while trying to evaluate your expression."
	},
	easterEggs: true, // toggle Easter eggs :-)
	userfriendly: false,
	actDice: true // output <x>d<y> as /me rolls a d<y> x times: a, b, c; total: d
};
module.abuse = /load|run|java|ecma|op|doc|cli|(?:qui|exi|aler|prin|insul|impor|scrip)t|def|raw|throw|win|nan|open|con|p(?:ro|atch|lug|lay)|inf|my|for|(?:fals|minimi[sz]|dat|los|whil|writ|tru|typ)e|read|this|js|sys|scr|(?:de|loca|unti|rctr|eva)l|glob|[\[{'"}\]]/;
module.list = "Functions [<x>()]: acos, asin, atan, atan2, cos, sin, tan, exp, ln, pow, sqrt, abs, ceil, max, min, floor, round, random, randint, fact, mean, dice, ftoc, ctof. Constants: e, pi, phi, c. Operators: %, ^, **. Other topics: decimal, trig.";

module["cmd_="] = module.cmd_calc = module.cmd_math = function cmd_calc(dest, msg, nick, ident, host, conn, relay) {
	msg = msg.replace(/(?:\/\/|@).*$/, "").toLowerCase();
	if (msg.match(this.abuse)) {
		if (this.prefs.abuse.warn && !relay)
			conn.send("NOTICE", nick, ":Whoa! Careful dude!");
		writeln("[WARNING] Abuse detected! ^^^^^");
		if (this.prefs.abuse.log)
			aucgbot.log(conn, "CALC ABUSE", nick + (dest != nick ? " in " + dest : ""), msg);
		return true;
	}
	try {
		var s;
		if (/^(\d*)d(\d+)$/.test(msg))
			conn.msg(dest, this.cmdDice(RegExp.$2, RegExp.$1));
		else if ((s = this.parseMsg(msg)))
			conn.reply(dest, nick, s);
	} catch (ex) {
		writeln("[ERROR] ", ex);
		if (this.prefs.error.log)
			aucgbot.log(conn, "CALC ERROR", nick + (dest != nick ? " in " + dest : ""), msg, ex);
		if (this.prefs.error.apologise)
			conn.reply(dest, nick, this.prefs.error.apologymsg);
		if (this.prefs.error.sendError)
			conn.reply(dest, nick, ex);
	}
	return true;
};
module.cmd_base = function cmd_base(dest, msg, nick, ident, host, conn, relay) {
	var args = msg.split(" ");
	if (args.length < 2 || args.length > 3)
		conn.reply(dest, nick, "Invalid usage. Usage: base <num> <fromBase> [<toBase>]");
	else
		conn.reply(dest, nick, parseInt(args[0], args[1]).toString(parseInt(args[2]) || 10));
	return true;
};
module.cmd_base10 = function cmd_base10(dest, msg, nick, ident, host, conn, relay) {
	var args = msg.split(" ");
	if (args.length != 2)
		conn.reply(dest, nick, "Invalid usage. Usage: base <num> <fromBase> [<toBase>]");
	else
		conn.reply(dest, nick, (+args[0]).toString(+args[1]));
	return true;
}
module.cmd_qe = function cmd_quadraticEqn(dest, msg, nick, ident, host, conn, relay) {
	var a, b, c, _2a, pron, resInSqrt, resSqrt, res = [];
	if (!/^(?:([+\-]?\d*(?:\.\d*)?) ?\*? ?)?([A-Za-z]) ?(?:\*\*|\^) ?2 ?(?:([+\-] ?\d*(?:\.\d*)?) ?\*? ?\2)? ?([+\-] ?\d*(?:\.\d*)?)? ?= ?([+\-]?\d*(?:\.\d*)?)$/.test(msg)) {
		// not a quadratic equation, bail
		conn.reply(dest, nick, "qe: Evaluates the value of the pronumeral in a quadratic equation in general form i.e. ax**2 + bx + c = 0");
		return true;
	}
{'fraction_non_alphanumeric': 0.22171297622457747, 'fraction_numerical': 0.009882555141793183, 'mean_word_length': 4.085943190094683, 'pattern_counts': {'":': 2, '<': 22, '<?xml version=': 0, '>': 22, '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': '166298', 'n_tokens_mistral': 2884, 'n_tokens_neox': 2737, 'n_words': 715}