let oyndurum = new Set();
const kelime = require('../../utils/Words.json');

module.exports = {
  name: "adam-asmaca",
  description: "Adam asmaca oynatÄ±r.",
  usage: "adam-asmaca",
  aliases: ["adamasmaca"],
  category: "Games",
  memberPermissions: [],
  botPermissions: ["SendMessages", "EmbedLinks"],
  nsfw: false,
  cooldown: false,
  ownerOnly: false,

  async execute(client, message, args, data) {

    if (oyndurum.has(message.channel.id)) return message.channel.send({
      embeds: [
        {
          color: client.settings.embedColors.red,
          title: '**Â»** Bu Kanalda Devam Eden Bir Oyun Bulunuyor!',
          description: `**â€¢** Oyunun bitmesini bekleyebilir veya farklÄ± kanalda deneyebilirsin.`
        }
      ]
    });

    try {
      const cevap = kelime[Math.floor(Math.random() * kelime.length)].toLocaleLowerCase('tr-TR');
      let point = 0;
      let displayText = null;
      let tahmin = false;
      const confirmation = [];
      const yanlÄ±ÅŸ = [];
      const display = new Array(cevap.length).fill('_');
      while (cevap.length !== confirmation.length && point < 8) {
        await message.channel.send(
          `${displayText === null ? '**Nraphy Adam Asmaca**!' : displayText ? '**Ã‡ok iyisin!**' : '**YanlÄ±ÅŸ Harf!**'}\n` +
          `**Kelime:**    \`${display.join(' ')}\`\n` +
          `**YanlÄ±ÅŸ Harfler:** ${yanlÄ±ÅŸ.join(', ') || 'Yok'}\n` +
          `\`\`\`\n` +
          `___________\n` +
          `|     |\n` +
          `|     ${point > 0 ? 'ðŸ˜µ' : ''}\n` +
          `|    ${point > 3 ? 'â”Œ' : ' '}${point > 1 ? '(' : ''}${point > 2 ? ')' : ' '}${point > 4 ? 'â”�' : ''}\n` +
          `|     ${point > 5 ? '/' : ''}${point > 6 ? '\\' : ''}\n` +
          `|\n` +
          `\`\`\``);
        const filter = res => {
          const choice = res.content.toLocaleLowerCase('tr-TR');
          return res.author.id === message.author.id && !confirmation.includes(choice) && !yanlÄ±ÅŸ.includes(choice);
        };
        const guess = await message.channel.awaitMessages({ filter, max: 1, time: 20000 });
        if (!guess.size) {
          await message.channel.send({
            embeds: [
              {
                color: client.settings.embedColors.red,
                description: `**Â»** ÃœzgÃ¼nÃ¼m, sÃ¼ren doldu.`
              }
            ]
          });
          break;
        }
        const choice = guess.first().content.toLocaleLowerCase('tr-TR');
        if (choice === 'end') break;
        if (choice.length > 1 && choice === cevap) {
          tahmin = true;
          break;
        } else if (cevap.includes(choice)) {
          displayText = true;
          for (let i = 0; i < cevap.length; i++) {
            if (cevap.charAt(i) !== choice) continue;
            confirmation.push(cevap.charAt(i));
            display[i] = cevap.charAt(i);
          }
        } else {
          displayText = false;
          if (choice.length === 1) yanlÄ±ÅŸ.push(choice);
          point++;
        }
      }
      oyndurum.delete(message.channel.id);
      if (cevap.length === confirmation.length || tahmin) return message.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.green,
            title: `**Â»** Tebrikler Kelimeyi Buldun! ðŸ�†`,
            description: `**â€¢** ${client.capitalizeFirstLetter(cevap, "tr")}`
          }
        ]
      });
      return message.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: `**Â»** Maalesef Bilemedin!`,
            description: `**â€¢** Tahmin edemediÄŸin kelime: **${client.capitalizeFirstLetter(cevap, "tr")}**`
          }
        ]
      });
    } catch (err) {
      oyndurum.delete(message.channel.id);
      return message.channel.send({
        embeds: [
          {
            color: client.settings.embedColors.red,
            title: `**Â»** Bir Hata OluÅŸtu!`,
            description: `\`\`\`${err.message}\`\`\``
          }
        ]
      });
    }
  }
};