const Command = require("../../base/Command"),
	fetch = require("node-fetch");

class Love extends Command {
	constructor(client) {
		super(client, {
			name: "love",
			dirname: __dirname,
			enabled: true,
			guildOnly: false,
			aliases: [],
			memberPermissions: [],
			botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "ATTACH_FILES"],
			nsfw: false,
			ownerOnly: false,
			cooldown: 3000
		});
	}

	async run(message, args) {
		const users = [
			await this.client.resolveUser(args[0]) || message.author,
			await this.client.resolveUser(args[1]) || message.author
		];

		const m = await message.sendT("misc:PLEASE_WAIT", null, {
			prefixEmoji: "loading"
		});
		try {
			const res = await fetch(encodeURI(`https://nekobot.xyz/api/imagegen?type=ship&user1=${users[0].displayAvatarURL({ format: "png", size: 512 })}&user2=${users[1].displayAvatarURL({ format: "png", size: 512 })}`));
			const json = await res.json();
			message.channel.send({
				files: [{
					name: "love.png",
					attachment: json.message
				}]
			});
			m.delete();
		} catch (e) {
			console.log(e);
			m.error("misc:ERR_OCCURRED", null, {
				edit: true
			});
		}
	}
}

module.exports = Love;