<commit_before>var opener = require('./opener');
var nconf = require('nconf').file({file:'./config.json'});
var defaults = nconf.get('defaults');

module.exports = {

	respond : function (req, res, next) {
		var text = req.body.text;
		var trigger = req.body.trigger_word;

		if (text && trigger) {
			text = text.replace(trigger, '');

			opener(text, function (error, reply) {
				if (error) {
					next(error);
				} else if (reply) {
					reply = merge(defaults, reply);
					res.status(200).json(reply);
				} else {
					res.end();
				}
			});
		} else {
			res.end();
		}
	}
};


function merge (object, source) {
	for (var key in source) {
		if (source.hasOwnProperty(key)) {
			object[key] = source[key];
		}
	}

	return object;
}<commit_msg>clone object when merging<commit_after>var opener = require('./opener');
var nconf = require('nconf').file({file:'./config.json'});
var defaults = nconf.get('defaults');

module.exports = {

	respond : function (req, res, next) {
		var text = req.body.text;
		var trigger = req.body.trigger_word;

		if (text && trigger) {
			text = text.replace(trigger, '');

			opener(text, function (error, reply) {
				if (error) {
					next(error);
				} else if (reply) {
					reply = merge(defaults, reply);
					res.status(200).json(reply);
				} else {
					res.end();
				}
			});
		} else {
			res.end();
		}
	}
};


function merge (object, source) {
	var copy = {};

	for (var key in object) {
		if (object.hasOwnProperty(key)) {
			copy[key] = object[key];
		}
	}

	for (var key in source) {
		if (source.hasOwnProperty(key)) {
			copy[key] = source[key];
		}
	}

	return copy;
}
{'fraction_non_alphanumeric': 0.17997542997542998, 'fraction_numerical': 0.0036855036855036856, 'mean_word_length': 2.9828850855745723, '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': '7496030', 'n_tokens_mistral': 686, 'n_tokens_neox': 576, 'n_words': 132}