const { Command } = require('discord.js-commando');

module.exports = class PigLatinCommand extends Command {
	constructor(client) {
		super(client, {
			name: 'pig-latin',
			group: 'text-edit',
			memberName: 'pig-latin',
			description: 'Converts text to pig latin.',
			args: [
				{
					key: 'text',
					prompt: 'What text would you like to convert to pig latin?',
					type: 'string',
					validate: text => {
						if (this.pigLatin(text).length < 2000) return true;
						return 'Invalid text, your text is too long.';
					}
				}
			]
		});
	}

	run(msg, { text }) {
		return msg.say(this.pigLatin(text));
	}

	pigLatin(text) {
		return text.replace(/\w+/g, this.pigLatinWord).toLowerCase();
	}

	pigLatinWord(word) {
		return `${word.slice(1)}${word.charAt(0)}ay`;
	}
};
