From a6c1e89d29581646821906e7a0e1ba52bcd5e284 Mon Sep 17 00:00:00 2001 From: SkulZOnTheYT <92020118+SkulZOnTheYT@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:07:54 +0700 Subject: [PATCH] Add files via upload --- plugins/game/akinator.js | 47 ++++++++++++++++++++++++++++++++++++ plugins/game/akinator_ans.js | 40 ++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 plugins/game/akinator.js create mode 100644 plugins/game/akinator_ans.js diff --git a/plugins/game/akinator.js b/plugins/game/akinator.js new file mode 100644 index 0000000..25a7395 --- /dev/null +++ b/plugins/game/akinator.js @@ -0,0 +1,47 @@ +import db from '../../lib/database.js' + +let handler = async (m, { conn, usedPrefix, command, text }) => { + let aki = m.isGroup ? db.data.chats[m.chat].akinator : db.data.users[m.sender].akinator + if (text == 'end') { + if (!aki.sesi) return m.reply('Tidak sedang dalam sesi Akinator') + aki.sesi = false + aki.soal = null + m.reply('Berhasil keluar dari sesi Akinator.') + } else { + if (aki.sesi) return conn.reply(m.chat, `Masih berada dalam sesi Akinator\n*${usedPrefix + command} end* untuk keluar dari sesi Akinator`, aki.soal) + try { + let anu = await (await fetch(`https://api.lolhuman.xyz/api/akinator/start?apikey=${api.lol}`)).json() + if (anu.status != 200) throw Error(anu.message) + let { server, frontaddr, session, signature, question, progression, step } = anu.result + aki.sesi = true + aki.server = server + aki.frontaddr = frontaddr + aki.session = session + aki.signature = signature + aki.question = question + aki.progression = progression + aki.step = step + let txt = `🎮 *Akinator* 🎮\n\n@${m.sender.split('@')[0]}\n ${question}\n\n` + txt += '0 - Ya\n' + txt += '1 - Tidak\n' + txt += '2 - Saya Tidak Tau\n' + txt += '3 - Mungkin\n' + txt += '4 - Mungkin Tidak\n\n' + txt += `*${usedPrefix + command} end* untuk keluar dari sesi Akinator` + let soal = await conn.reply(m.chat, txt, m, { mentions: [m.sender] }) + aki.soal = soal + } catch (e) { + console.log(e) + throw 'server down' + } + } +} + +handler.menufun = ['akinator'] +handler.tagsfun = ['game'] +handler.command = /^(akinator)$/i + +handler.limit = true +handler.game = true + +export default handler \ No newline at end of file diff --git a/plugins/game/akinator_ans.js b/plugins/game/akinator_ans.js new file mode 100644 index 0000000..baca47f --- /dev/null +++ b/plugins/game/akinator_ans.js @@ -0,0 +1,40 @@ +import db from '../../lib/database.js' +import { somematch } from '../../lib/func.js' + +const teks = '0 - Ya\n1 - Tidak\n2 - Saya Tidak Tau\n3 - Mungkin\n4 - Mungkin Tidak\n5 - Kembali ke pertanyaan sebelumnya' + +export async function before(m) { + if (!m.quoted || !m.quoted.fromMe || !m.quoted.isBaileys || !m.text) return !1 + let user = db.data.users[m.sender] + let aki = m.isGroup ? db.data.chats[m.chat].akinator : user.akinator + if (!aki.sesi || m.quoted.id != aki.soal.key.id) return + if (!somematch(['0','1','2','3','4','5'], m.text)) return this.reply(m.chat, `[!] Jawab dengan angka 1, 2, 3, 4, atau 5\n\n${teks}`, aki.soal) + let { server, frontaddr, session, signature, question, progression, step } = aki + if (step == '0' && m.text == '5') return m.reply('Anda telah mencapai pertanyaan pertama') + try { + user.spamcount += 1 + let anu = await (await fetch(`https://api.lolhuman.xyz/api/akinator/${m.text == '5' ? 'back' : 'answer'}?apikey=${api.lol}&server=${server}${m.text == '5' ? `&session=${session}&signature=${signature}&step=${step}` : `&frontaddr=${frontaddr}&session=${session}&signature=${signature}&step=${step}&answer=${m.text}`}`)).json() + if (anu.status != 200) { + aki.sesi = false + aki.soal = null + return m.reply(anu.message) + } + anu = anu.result + if (anu.name) { + await this.sendMsg(m.chat, { image: { url: anu.image }, caption: `🎮 *Akinator Answer* 🎮\n\nDia adalah *${anu.name}*\n_${anu.description}_`, mentions: [m.sender] }, { quoted: m }) + aki.sesi = false + aki.soal = null + } else { + let soal = await this.reply(m.chat, `🎮 *Akinator* 🎮\n_step ${anu.step} ( ${anu.progression.toFixed(2)} % )_\n\n@${m.sender.split('@')[0]}\n ${anu.question}\n\n${teks}`, m, { mentions: [m.sender] }) + aki.soal = soal + aki.step = anu.step + aki.progression = anu.progression + } + } catch (e) { + console.log(e) + aki.sesi = false + aki.soal = null + m.reply('server down') + } + return !0 +} \ No newline at end of file