{"size": 1177, "ext": "js", "max_stars_repo_path": "commands/note.js", "max_stars_repo_name": "fennectech/Korral-JS", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "commands/note.js", "max_issues_repo_name": "fennectech/Korral-JS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "commands/note.js", "max_forks_repo_name": "fennectech/Korral-JS", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.0204081633, "max_line_length": 119, "alphanum_fraction": 0.6482582838}
module.exports = {
	name: 'note',
	description: 'Adds a note to a user.',
	usage: '<user> <note>',
	cooldown: 0,
	staff: true,
	execute(message, args) {

		function returnResponse(reponse = "Something happened but no response was defined.") {
			message.channel.send(reponse);
		}

		if (message.mentions.members.first()) {
			var mentionedUser = message.mentions.members.first();
		} else {
			returnResponse(`No user was mentioned.`);
			return;
		}

		if (!args[1]) {
			returnResponse(`Please provide a note.`)
			return;
		}

		var reason = args.join(' ').replace(args[0], '')

		// all requirements are met
		var config = require('../config.json');
		var notes = require('../userNotes.json')

		if (!notes[mentionedUser.id])
			notes[mentionedUser.id] = [];

		notes[mentionedUser.id].push(reason);

		fs.writeFile('./userNotes.json', JSON.stringify(notes), (err) => {
			if (err) {
				console.log(err);
				returnResponse(`An error occured during saving.`);
				return;
			}

			message.channel.send(`<@${mentionedUser.id}> had a note added. User has ${notes[mentionedUser.id].length} note(s).`)
			delete require.cache[require.resolve(`../warnings.json`)]
		})

	}
};
