{"size": 912, "ext": "js", "max_stars_repo_path": "handlers.js", "max_stars_repo_name": "MikhailKhromov/unnamedBot", "max_stars_repo_stars_event_min_datetime": "2020-08-28T23:14:10.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-19T13:57:25.000Z", "max_issues_repo_path": "handlers.js", "max_issues_repo_name": "MikhailKhromov/unnamedBot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "handlers.js", "max_forks_repo_name": "MikhailKhromov/unnamedBot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.5, "max_line_length": 69, "alphanum_fraction": 0.7072368421}
const command_objects = require('./commands/')
const custom_commands = require('./commands.json')
const database = require('./database.js')

exports.commandHandler = function(username, message, callback) {
	message = message.slice(1).split(' ');
	let command = message[0].toLowerCase();
	message.shift();
	let args = message;
	// check if it's a command in /commands/ folder
	for (const el in command_objects) {
		let obj = command_objects[el]
		if (obj.command_name.includes(command)) {
			obj.call(username, args, callback);
			break;
		}
	}
	// maybe command is not there, and in the commands.json file instead
	for (const el in custom_commands) {
		let obj = custom_commands[el]
		if (obj.command_name.includes(command)) {
			callback(obj.call)
		}
	}
	// it's not there. ignore it
};


exports.messageHandler = function(username, message) {
	database.addTextMessage(username, message, Date.now() / 1000)
};
