const config = require('config');
const utils = require('./../../utils.js');

module.exports.alias = [
	'js',
	'javascript'
];

module.exports.command = (message) => {
	if (config.get('admins').includes(message.author.id)) {
		const embed = {
			embed: {
				title: 'MSS-Discord',
				fields: [
					{
						name: 'Input',
						value: message.input,
					}
				]
			}
		};

		try {
			const output = eval(`(${message.input})`); // eslint-disable-line no-eval
			if (output.length < 500) {
				embed.embed.fields.push({ name: 'Output', value: `\`\`\`\n${output}\n\`\`\`` });
				return message.channel.createMessage(embed);
			}
			utils.gist(message.content, (url) => {
				embed.embed.fields.push({ name: 'Output', value: `[GitHub Gist](${url})` });
				return message.channel.createMessage(embed);
			});
		} catch (err) {
			utils.gist(err.stack, (url) => {
				embed.embed.fields.push({ name: 'Error', value: `[GitHub Gist](${url})` });
				return message.channel.createMessage(embed);
			});
		}
	}
	return false;
};

@@ -470,16 +470,26 @@
 tput
+ && output
 .length 
 %3C 50
@@ -488,9 +488,9 @@
 gth 
-%3C
+%3E
  500
@@ -631,20 +631,63 @@
 d);%0A%09%09%09%7D
+ else if (typeof output !== 'undefined') %7B
 %0A%09%09%09
+%09
 utils.gi
@@ -709,32 +709,33 @@
 ent, (url) =%3E %7B%0A
+%09
 %09%09%09%09embed.embed.
@@ -795,32 +795,33 @@
 %7Burl%7D)%60 %7D);%0A%09%09%09%09
+%09
 return message.c
@@ -849,23 +849,110 @@
 embed);%0A
+%09
 %09%09%09%7D);%0A
+%09%09%09%7D else %7B%0A%09%09%09%09embed.embed.fields.push(%7B name: 'Output', value: 'Undefined' %7D);%0A%09%09%09%7D%0A
 %09%09%7D catc

add undefined