<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/. */
/*jshint es5: true, esnext: true, forin: true, proto: true */
/*global Stream: false, aucgbot: false, module: false */

// PLEASE NOTE: if you edit the badwords list using the rc js command, also
// `this.modules.badword.parseList()` otherwise it will not work

module.version = "5.4 (2013-11-21)";
module.db = {}, module.sfwChans = [];
module.DB_FILENAME = "badword.json";
module.spaceAfterColon = false;

module.parseList = function parseList() {
	var badwords = [];
	for (var word in this.badwords) {
		if (this.badwords.hasOwnProperty(word) && typeof this.badwords[word] === "string")
			badwords.push(this.badwords[word]);
	}
	this.badwordList = RegExp(badwords.join("|"));
};
module.loadDB = function loadDB() {
	var file;
	try {
		file = new Stream(this.DB_FILENAME);
		this.db = JSON.parse(file.readFile());
	} catch (ex) {}
	if (file && typeof file.close === "function")
		file.close();
	/* hasOwnProperty __proto__ hack: __proto__ === null => hasOwnProperty returns false
	 *
	 * We don't want to define __proto__ if __proto__ has been removed
	 * or if hasOwnProperty("__proto__") => false already.
	 * This seems to have interesting effects.
	 * Do not use this unless you really need it and it actually works properly.
	 *
	 * uneval(obj): "null"
	 * Boolean(obj), !!obj: true
	 * JSON.stringify(obj): {...}
	 * String(obj): TypeError: can't convert obj to string
	 * obj + "": TypeError: can't convert obj to primitive type
	 * Number(obj), +obj: TypeError: can't convert obj to number
	 * Firefox web console: TypeError: can't convert null to primitive type
	 *                                            wat^
	 * v8: Object.hasOwnProperty(obj, x): TypeError: Cannot convert object to primitive value
	 */
	//if (this.db.__proto__ === Object.prototype && Object.prototype.hasOwnProperty.call({}, "__proto__"))
		//this.db.__proto__ = null;
};
module.saveDB = function saveDB() {
	var file = new Stream(this.DB_FILENAME, "w");
	file.write(JSON.stringify(this.db));
	file.close();
};
/**
 * Get a user's database entry.
 *
 * @param {string} nick User's nickname.
 * @param {boolean} [create] Whether the entry should be created if it does not exist.
 * @param {boolean} [noAlts] Whether to not recursively get alternate nicks.
 * @return {Object} The database entry.
 */
module.getUser = function getUser(nick, create, noAlts) {
	const name = nick.toLowerCase();
	var db;<commit_msg>badword.jsm: horrible horrible file stuff<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/. */
/*jshint es5: true, esnext: true, forin: true, proto: true */
/*global Stream: false, aucgbot: false, module: false */

// PLEASE NOTE: if you edit the badwords list using the rc js command, also
// `this.modules.badword.parseList()` otherwise it will not work

module.version = "5.4.1 (2015-01-19)";
module.db = {}, module.sfwChans = [];
module.DB_FILENAME = "badword.json";
module.spaceAfterColon = false;

module.parseList = function parseList() {
	var badwords = [];
	for (var word in this.badwords) {
		if (this.badwords.hasOwnProperty(word) && typeof this.badwords[word] === "string")
			badwords.push(this.badwords[word]);
	}
	this.badwordList = RegExp(badwords.join("|"));
};
module.loadDB = function loadDB() {
	try {
		this.db = JSON.parse(aucgbot.readFile(this.DB_FILENAME));
	} catch (ex) {}
	/* hasOwnProperty __proto__ hack: __proto__ === null => hasOwnProperty returns false
	 *
	 * We don't want to define __proto__ if __proto__ has been removed
	 * or if hasOwnProperty("__proto__") => false already.
	 * This seems to have interesting effects.
	 * Do not use this unless you really need it and it actually works properly.
	 *
	 * uneval(obj): "null"
	 * Boolean(obj), !!obj: true
	 * JSON.stringify(obj): {...}
	 * String(obj): TypeError: can't convert obj to string
	 * obj + "": TypeError: can't convert obj to primitive type
	 * Number(obj), +obj: TypeError: can't convert obj to number
	 * Firefox web console: TypeError: can't convert null to primitive type
	 *                                            wat^
	 * v8: Object.hasOwnProperty(obj, x): TypeError: Cannot convert object to primitive value
	 */
	//if (this.db.__proto__ === Object.prototype && Object.prototype.hasOwnProperty.call({}, "__proto__"))
		//this.db.__proto__ = null;
};
module.saveDB = function saveDB() {
	aucgbot.writeFile(this.DB_FILENAME, JSON.stringify(this.db));
};
/**
 * Get a user's database entry.
 *
 * @param {string} nick User's nickname.
 * @param {boolean} [create] Whether the entry should be created if it does not exist.
 * @param {boolean} [noAlts] Whether to not recursively get alternate nicks.
 * @return {Object} The database entry.
 */
module.getUser = function getUser(nick, create, noAlts) {
	const name = nick.toLowerCase();
	var db;
{'fraction_non_alphanumeric': 0.13855763770584895, 'fraction_numerical': 0.007003596441415862, 'mean_word_length': 3.7517985611510793, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604245', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1620, 'n_words': 555}