forked from ariffb25/stikerinbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ariffb25#199 from syahrularranger/main
pvp suit
- Loading branch information
Showing
2 changed files
with
134 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,40 @@ | ||
/* | ||
Made by https://github.com/syahrularranger | ||
Jangan di hapus credit nya :) | ||
*/ | ||
let timeout = 60000 | ||
let poin = 500 | ||
let poin_lose = -100 | ||
let handler = async (m, { conn, usedPrefix }) => { | ||
conn.suit = conn.suit ? conn.suit : {} | ||
if (Object.values(conn.suit).find(room => room.id.startsWith('suit') && [room.p, room.p2].includes(m.sender))) throw 'Selesaikan suit mu yang sebelumnya' | ||
if (!m.mentionedJid[0]) return m.reply(`_Siapa yang ingin kamu tantang?_\nTag orangnya.. Contoh\n\n${usedPrefix}suit @${owner[1]}`, m.chat, { contextInfo: { mentionedJid: [owner[1] + '@s.whatsapp.net'] } }) | ||
if (Object.values(conn.suit).find(room => room.id.startsWith('suit') && [room.p, room.p2].includes(m.mentionedJid[0]))) throw `Orang yang kamu tantang sedang bermain suit bersama orang lain :(` | ||
let id = 'suit_' + new Date() * 1 | ||
let caption = ` | ||
_*SUIT PvP*_ | ||
@${m.sender.split`@`[0]} menantang @${m.mentionedJid[0].split`@`[0]} untuk bermain suit | ||
Silahkan @${m.mentionedJid[0].split`@`[0]} | ||
`.trim() | ||
let footer = `Ketik "terima/ok/gas" untuk memulai suit\nKetik "tolak/gabisa/nanti" untuk menolak` | ||
conn.suit[id] = { | ||
chat: await conn.send2Button(m.chat, caption, footer, 'Terima', 'ok', 'Tolak', 'tolak', m, { contextInfo: { mentionedJid: conn.parseMention(caption) } }), | ||
id: id, | ||
p: m.sender, | ||
p2: m.mentionedJid[0], | ||
status: 'wait', | ||
waktu: setTimeout(() => { | ||
if (conn.suit[id]) conn.reply(m.chat, `_Waktu suit habis_`, m) | ||
delete conn.suit[id] | ||
}, timeout), poin, poin_lose, timeout | ||
} | ||
} | ||
handler.tags = ['game'] | ||
handler.help = ['suitpvp', 'suit'].map(v => v + ' @tag') | ||
handler.command = /^suit(pvp)?$/i | ||
handler.limit = false | ||
handler.group = true | ||
|
||
module.exports = 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,94 @@ | ||
let handler = m => m | ||
handler.before = async function (m) { | ||
this.suit = this.suit ? this.suit : {} | ||
if (db.data.users[m.sender].suit < 0) db.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) | ||
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.send3Button(room.p, 'Silahkan pilih', `Menang +${room.poin}XP\nKalah -${room.poin_lose}XP`, 'Batu🗿', 'Batu', 'Kertas📄', 'Kertas', 'Gunting✂️', 'Gunting', m) | ||
if (!room.pilih2) this.send3Button(room.p2, 'Silahkan pilih', `Menang +${room.poin}XP\nKalah -${room.poin_lose}XP`, 'Batu🗿', 'Batu', 'Kertas📄', 'Kertas', 'Gunting✂️', 'Gunting', 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) | ||
db.data.users[win == room.p ? room.p : room.p2].exp += room.poin | ||
db.data.users[win == room.p ? room.p2 : room.p].exp -= 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}XP` : ` Kalah \n-${room.poin_lose}XP`} | ||
@${room.p2.split`@`[0]} (${room.text2}) ${tie ? '' : room.p2 == win ? ` Menang \n+${room.poin}XP` : ` Kalah \n-${room.poin_lose}XP`} | ||
`.trim(), m, { contextInfo: { mentionedJid: [room.p, room.p2] } }) | ||
if (!tie) { | ||
db.data.users[win == room.p ? room.p : room.p2].exp += room.poin | ||
db.data.users[win == room.p ? room.p2 : room.p].exp += 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)] | ||
} |