<commit_before>//set main entry point path
global.BOT_DIR = require('path').resolve(__dirname, '..');
global.LIBS_DIR = require('path').resolve(BOT_DIR, 'libs');
global.MODULES_DIR = require('path').resolve(BOT_DIR, 'modules');

var logger = require(LIBS_DIR + '/logger');
var helpers = require(LIBS_DIR + '/helpers');

process.setMaxListeners(0); //fix the possible memory leak warning, by unlimiting listeners

function Bot() {
	//events
	var dispatcher = new(require('events').EventEmitter)();
	dispatcher.setMaxListeners(0); //remove listener limit
	//add empty config
	var config = new(require(LIBS_DIR + '/config').Config)();
	//add MM
	var moduleManager = new(require(LIBS_DIR + '/moduleManager').ModuleManager)(dispatcher, config);

	//load module on new listener
	dispatcher.on('newListener', function(event, listener) {
		var i, name;
		if (((i = event.indexOf('/')) + 1) && (name = event.substr(0, i))) {
			if (!moduleManager.exists(name)) {
				//better to not load modules automagically
				//moduleManager.load(name);
				logger.warn('Added new listener (' + event + ') for not loaded module!');
			}
		}
	});

	//bot config
	this.config = config;
	this._configWatch = null;
	//bot MM
	this.modules = moduleManager;
	//dispatcher
	this.dispatcher = dispatcher;

	//list of core modules
	this.core_modules = {
		'irc': true,
		'controls': true,
		'nickserv': true
	};

	this.halting = false;

	//bind to exit event of main process
	var bot = this;
	process.on('exit', function() {
		if (!bot.halting) bot.emit('halt', bot);
		bot.unloadModules();
	});

	//shutdown on ctrl+c gracefully
	process.on('SIGINT', function() {
		bot.halting = true;
		logger.info(':SIGINT Received, Exiting ...');
		bot.emit('halt', bot);
		setTimeout(process.exit, 1000);
	});

	// This will override SIGTSTP and prevent the program from going to the background.
	process.on('SIGTSTP', function() {});
}

Bot.prototype.addListener = function() {
	this.dispatcher.addListener.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.on = function() {
	this.dispatcher.on.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.off = Bot.prototype.removeListener = function() {
	this.dispatcher.removeListener.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.once = function() {
	this.dispatcher.once.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.emit = function() {
	this.dispatcher.emit.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.loadConfig = function loadConfig(config, callback) {
	var bot = this;

	var error = null;
	if (typeof config === 'function' && typeof callback === 'undefined') {
		callback = config;
		config = undefined;
	}

	if (bot._configWatch) { //stop watching config
		bot._configWatch.close();
		bot._configWatch = null;
	}

	if (typeof config === 'string') {
		try {
			bot.config.extend(require(BOT_DIR + '/' + config));
			bot._configWatch = require('fs').watch(BOT_DIR + '/' + config, {
				persistent: false
			}, function(event, filename) {
				if (event === 'change') {
					bot.loadConfig(filename);
				}
			});
		} catch (e) {
			logger.error('Cannot load config!');
			error = new Error('Cannot load config!');
		}
	} else if (config instanceof Object) {
		bot.config.extend(config);
	} else {
		try {
			bot.config.extend(require(BOT_DIR + '/config.json'));
			bot._configWatch = require('fs').watch(BOT_DIR + '/config.json', {
				persistent: false
			}, function(event, filename) {
				if (event === 'change') {
					bot.loadConfig(filename);
				}
			});
		} catch (e) {
			logger.error('Cannot load config!');
			error = new Error('Cannot load config!');
		}
	}

	//make sure we have important values
	if (typeof bot.config.bot === 'undefined') {
		bot.config.bot = {
			'name': 'IRC-PONY',
			'modules': 'modules.json'
		};
	} else {
		if (typeof bot.config.bot.name === 'undefined') {
			bot.config.bot.name = 'IRC-PONY';
		}
		if (typeof bot.config.bot.modules === 'undefined') {
			bot.config.bot.modules = 'modules.json';
		}
	}

	if (callback) callback(error, bot.config);
	else if (error) throw error;

	logger.info('Config loaded!');

	if (logger && typeof bot.config.bot.debug === 'boolean') {
		logger.debugging = bot.config.bot.debug;
	}

	return bot;
};

Bot.prototype.loadModules = function loadModules(modules, callback) {<commit_msg>can stop debug<commit_after>//set main entry point path
global.BOT_DIR = require('path').resolve(__dirname, '..');
global.LIBS_DIR = require('path').resolve(BOT_DIR, 'libs');
global.MODULES_DIR = require('path').resolve(BOT_DIR, 'modules');

var logger = require(LIBS_DIR + '/logger');
var helpers = require(LIBS_DIR + '/helpers');

process.setMaxListeners(0); //fix the possible memory leak warning, by unlimiting listeners

function Bot() {
	//events
	var dispatcher = new(require('events').EventEmitter)();
	dispatcher.setMaxListeners(0); //remove listener limit
	//add empty config
	var config = new(require(LIBS_DIR + '/config').Config)();
	//add MM
	var moduleManager = new(require(LIBS_DIR + '/moduleManager').ModuleManager)(dispatcher, config);

	//load module on new listener
	dispatcher.on('newListener', function(event, listener) {
		var i, name;
		if (((i = event.indexOf('/')) + 1) && (name = event.substr(0, i))) {
			if (!moduleManager.exists(name)) {
				//better to not load modules automagically
				//moduleManager.load(name);
				logger.warn('Added new listener (' + event + ') for not loaded module!');
			}
		}
	});

	//bot config
	this.config = config;
	this._configWatch = null;
	//bot MM
	this.modules = moduleManager;
	//dispatcher
	this.dispatcher = dispatcher;

	//list of core modules
	this.core_modules = {
		'irc': true,
		'controls': true,
		'nickserv': true
	};

	this.halting = false;

	//bind to exit event of main process
	var bot = this;
	process.on('exit', function() {
		if (!bot.halting) bot.emit('halt', bot);
		bot.unloadModules();
	});

	//shutdown on ctrl+c gracefully
	process.on('SIGINT', function() {
		bot.halting = true;
		logger.info(':SIGINT Received, Exiting ...');
		bot.emit('halt', bot);
		setTimeout(process.exit, 1000);
	});

	// This will override SIGTSTP and prevent the program from going to the background.
	process.on('SIGTSTP', function() {});
}

Bot.prototype.addListener = function() {
	this.dispatcher.addListener.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.on = function() {
	this.dispatcher.on.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.off = Bot.prototype.removeListener = function() {
	this.dispatcher.removeListener.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.once = function() {
	this.dispatcher.once.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.emit = function() {
	this.dispatcher.emit.apply(this.dispatcher, arguments);
	return this;
};

Bot.prototype.loadConfig = function loadConfig(config, callback) {
	var bot = this;

	var error = null;
	if (typeof config === 'function' && typeof callback === 'undefined') {
		callback = config;
		config = undefined;
	}

	if (bot._configWatch) { //stop watching config
		bot._configWatch.close();
		bot._configWatch = null;
	}

	if (typeof config === 'string') {
		try {
			bot.config.extend(require(BOT_DIR + '/' + config));
			bot._configWatch = require('fs').watch(BOT_DIR + '/' + config, {
				persistent: false
			}, function(event, filename) {
				if (event === 'change') {
					bot.loadConfig(filename);
				}
			});
		} catch (e) {
			logger.error('Cannot load config!');
			error = new Error('Cannot load config!');
		}
	} else if (config instanceof Object) {
		bot.config.extend(config);
	} else {
		try {
			bot.config.extend(require(BOT_DIR + '/config.json'));
			bot._configWatch = require('fs').watch(BOT_DIR + '/config.json', {
				persistent: false
			}, function(event, filename) {
				if (event === 'change') {
					bot.loadConfig(filename);
				}
			});
		} catch (e) {
			logger.error('Cannot load config!');
			error = new Error('Cannot load config!');
		}
	}

	//make sure we have important values
	if (typeof bot.config.bot === 'undefined') {
		bot.config.bot = {
			'name': 'IRC-PONY',
			'modules': 'modules.json'
		};
	} else {
		if (typeof bot.config.bot.name === 'undefined') {
			bot.config.bot.name = 'IRC-PONY';
		}
		if (typeof bot.config.bot.modules === 'undefined') {
			bot.config.bot.modules = 'modules.json';
		}
	}

	if (callback) callback(error, bot.config);
	else if (error) throw error;

	logger.info('Config loaded!');

	if (logger) {
		logger.debugging = bot.config.bot.debug ? true : false;
	}

	return bot;
};

Bot.prototype.loadModules = function loadModules(modules, callback) {
{'fraction_non_alphanumeric': 0.1672610146094559, 'fraction_numerical': 0.0018405613712182216, 'mean_word_length': 3.8980281690140846, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1241758', 'n_tokens_mistral': 3101, 'n_tokens_neox': 2866, 'n_words': 669}