forked from Paquito1923/elyasmd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
math_ans.js
26 lines (25 loc) · 976 Bytes
/
math_ans.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
let handler = m => m
handler.before = async function (m) {
if (!/^-?[0-9]+(\.[0-9]+)?$/.test(m.text)) return !0
let id = m.chat
if (!m.quoted || m.quoted.sender != this.user.jid || !/^Berapa hasil dari/i.test(m.quoted.text)) return !0
this.math = this.math ? this.math : {}
if (!(id in this.math)) return m.reply('Soal itu telah berakhir')
if (m.quoted.id == this.math[id][0].id) {
let math = JSON.parse(JSON.stringify(this.math[id][1]))
if (m.text == math.result) {
global.db.data.users[m.sender].exp += math.bonus
clearTimeout(this.math[id][3])
delete this.math[id]
m.reply(`*Jawaban Benar!*\n+${math.bonus} XP`)
} else {
if (--this.math[id][2] == 0) {
clearTimeout(this.math[id][3])
delete this.math[id]
m.reply(`*Kesempatan habis!*\nJawaban: *${math.result}*`)
} else m.reply(`*Jawaban Salah!*\nMasih ada ${this.math[id][2]} kesempatan`)
}
}
return !0
}
module.exports = handler