Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

) #197

Merged
merged 7 commits into from
Jan 29, 2022
Merged

) #197

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create suitpvp_ans.js
  • Loading branch information
unx21 authored Nov 14, 2021
commit ea0d4a14eeac3ee6d66e017402c4e0e4e873145e
94 changes: 94 additions & 0 deletions plugins/suitpvp_ans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
let handler = m => m
handler.before = async function (m) {
this.suit = this.suit ? this.suit : {}
if (global.DATABASE._data.users[m.sender].suit < 0) global.DATABASE._data.users[m.sender].suit = 0
let room = Object.values(this.suit).find(room => room.id && room.status && [room.p, room.p2].includes(m.sender))
if (room) {
let win = ''
let tie = false
if (m.sender == room.p2 && /^(acc(ept)?|terima|gas|oke?|tolak|gamau|nanti|ga(k.)?bisa)/i.test(m.text) && m.isGroup && room.status == 'wait') {
if (/^(tolak|gamau|nanti|ga(k.)?bisa)/i.test(m.text)) {
this.reply(m.chat, `@${room.p2.split`@`[0]} menolak suit, suit dibatalkan`, m, { contextInfo: { mentionedJid: [room.p2] } })
delete this.suit[room.id]
return !0
}
room.status = 'play'
room.asal = m.chat
clearTimeout(room.waktu)
//delete room[room.id].waktu
m.reply(`Suit telah dikirimkan ke chat
@${room.p.split`@`[0]} dan
@${room.p2.split`@`[0]}

Silahkan pilih suit di chat masing"
klik wa.me/${conn.user.jid.split`@`[0]}`, m.chat, {
contextInfo: {
mentionedJid: [room.p, room.p2]
}
})

if (!room.pilih) this.reply(room.p, ` *「 SUIT PVP 」*\n\nMenang +${room.poin} money\nKalah -${room.poin_lose} money\n\nBatu ✊🏻\nKertas 🖐🏻\nGunting ✌🏻`, m)
if (!room.pilih2) this.reply(room.p2, ` *「 SUIT PVP 」*\n\nMenang +${room.poin} money\nKalah -${room.poin_lose} money\n\nBatu ✊🏻\nKertas 🖐🏻\nGunting ✌🏻`, m)
room.waktu_milih = setTimeout(() => {
if (!room.pilih && !room.pilih2) this.reply(m.chat, `Kedua pemain tidak niat main,\nSuit dibatalkan`)
else if (!room.pilih || !room.pilih2) {
win = !room.pilih ? room.p2 : room.p
this.reply(m.chat, `@${(room.pilih ? room.p2 : room.p).split`@`[0]} tidak memilih suit, game berakhir`, m)
global.DATABASE._data.users[win == room.p ? room.p : room.p2].money += room.poin
global.DATABASE._data.users[win == room.p ? room.p2 : room.p].money -= room.poin_lose
}
delete this.suit[room.id]
return !0
}, room.timeout)
}
let jwb = m.sender == room.p
let jwb2 = m.sender == room.p2
let g = /gunting/i
let b = /batu/i
let k = /kertas/i
let reg = /^(gunting|batu|kertas)/i
if (jwb && reg.test(m.text) && !room.pilih && !m.isGroup) {
room.pilih = reg.exec(m.text.toLowerCase())[0]
room.text = m.text
m.reply(`Kamu telah memilih ${m.text} ${!room.pilih2 ? `\n\nMenunggu lawan memilih` : ''}`)
if (!room.pilih2) this.reply(room.p2, '_Lawan sudah memilih_\nSekarang giliran kamu', 0)
}
if (jwb2 && reg.test(m.text) && !room.pilih2 && !m.isGroup) {
room.pilih2 = reg.exec(m.text.toLowerCase())[0]
room.text2 = m.text
m.reply(`Kamu telah memilih ${m.text} ${!room.pilih ? `\n\nMenunggu lawan memilih` : ''}`)
if (!room.pilih) this.reply(room.p, '_Lawan sudah memilih_\nSekarang giliran kamu', 0)
}
let stage = room.pilih
let stage2 = room.pilih2
if (room.pilih && room.pilih2) {
clearTimeout(room.waktu_milih)
if (b.test(stage) && g.test(stage2)) win = room.p
else if (b.test(stage) && k.test(stage2)) win = room.p2
else if (g.test(stage) && k.test(stage2)) win = room.p
else if (g.test(stage) && b.test(stage2)) win = room.p2
else if (k.test(stage) && b.test(stage2)) win = room.p
else if (k.test(stage) && g.test(stage2)) win = room.p2
else if (stage == stage2) tie = true
this.reply(room.asal, `
_*Hasil Suit*_${tie ? '\nSERI' : ''}

@${room.p.split`@`[0]} (${room.text}) ${tie ? '' : room.p == win ? ` Menang \n+${room.poin} money` : ` Kalah \n-${room.poin_lose} money`}
@${room.p2.split`@`[0]} (${room.text2}) ${tie ? '' : room.p2 == win ? ` Menang \n+${room.poin} money` : ` Kalah \n-${room.poin_lose} money`}
`.trim(), m, { contextInfo: { mentionedJid: [room.p, room.p2] } })
if (!tie) {
global.DATABASE._data.users[win == room.p ? room.p : room.p2].money += room.poin
global.DATABASE._data.users[win == room.p ? room.p2 : room.p].money -= room.poin_lose

}
delete this.suit[room.id]
}
}
return !0
}
handler.exp = 0
module.exports = handler

function random(arr) {
return arr[Math.floor(Math.random() * arr.length)]
}