const Discord = require('discord.js'); //Biliyorsunuz anlatmaya gerek yok.
const db = require('quick.db') //Dosyaya yazma için quick.db
const prefix = "!" //Normal prefixiniz işte, kod hata vermesin diye var. Eğer zaten tanımlıysa yazmaya gerek yok.
const LIMITOR = 25 * 2 * 2 * 2;
const kelimeListesi = require("./kelimeler.json");
const delay = require("timers/promises").setTimeout;
client.on("messageCreate", async message => {
if (message.author.bot || message.channel.type === 'dm') return; //Bot ise dur
if (message.content.startsWith(prefix + "kelime")) { //yeni oyun
await message.channel.send("Oyun başladı\n\n" + "kelime") //kelimeyi yazar
db.set(`kelime_${message.channel.id}`, { topkelime: 0, sonharf: "e", kelimeler: ["kelime"] }) //son harfi not alır.
}
const oyun = db.get(`kelime_${message.channel.id}`);
if (!oyun) return;
const kelime = message.content.toLocaleLowerCase('tr'); //Mesajdaki kelimeyi çok gerekeceği için tanımladık
const { topkelime, sonharf, kelimeler } = oyun;
async function bitti(baslik) {
const embed = new Discord.MessageEmbed().setAuthor("Kelime oyunu")
.setTitle(baslik)
.addField("Son harfimiz şuydu:", sonharf, true)
.addField("Toplam doğru kelime:", String(topkelime), true)
await message.delete();
const mess = await message.channel.send({ embeds: [embed] });
await delay(2500);
return mess.delete();
}
if (kelime[0] !== sonharf)
return await bitti("Kelimenin ilk ile önceki kelimenin son harfi uyuşmuyor!");
if (kelime.length < 3)
return await bitti("Yazdığın kelime `3 harf`ten kısa!");
if (kelime.endsWith("ğ"))
return await bitti("Yazdığın kelime `Ğ` ile bitiyor!");
if (kelimeler.includes(kelime))
return await bitti(`Yazdığın kelime son \`${LIMITOR}\` kelime ile aynı!`);
if (!kelimeListesi.includes(kelime))
return await bitti("TDK'de kelime yok!");
await message.react("🆗").catch(_ => _)//Doğru ise emoji atar
//Kelimeleri not al
if (kelimeler.length >= LIMITOR) oyun.kelimeler.shift();
oyun.kelimeler.push(kelime);
oyun.sonharf = kelime.slice(-1);//son harfi yazdı
oyun.topkelime++;
db.set(`kelime_${message.channel.id}`, oyun);
});