-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
800a3e3
commit a6c1e89
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |