Skip to content

Commit

Permalink
FIX
Browse files Browse the repository at this point in the history
  • Loading branch information
Guru322 committed Jun 28, 2023
1 parent f7e0cb8 commit 6d70b28
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 210 deletions.
173 changes: 97 additions & 76 deletions plugins/econ-bet.js
Original file line number Diff line number Diff line change
@@ -1,95 +1,116 @@
let confirm = {}

async function handler(m, { conn, args }) {
//if (!isROwner) throw 'Dalam perbaikan'
if (m.sender in confirm) throw 'You are still gambling, wait for it to finish!!'
try {
let user = global.db.data.users[m.sender]
let count = (args[0] && number(parseInt(args[0])) ? Math.max(parseInt(args[0]), 1) : /all/i.test(args[0]) ? Math.floor(parseInt(user.money)) : 1) * 1
if ((user.money * 1) < count) return m.reply('💹 Your money is not enough!!')
if (!(m.sender in confirm)) {
confirm[m.sender] = {
sender: m.sender,
count,
timeout: setTimeout(() => (m.reply('timed out'), delete confirm[m.sender]), 60000)
}
let txt = `Are you sure you want to gamble (Y/n)\n\n*
Bet:* ${count} 💹\n⏰ 60s Timeout`
return conn.sendButton(m.chat, txt, author, null, [['✔️'], ['✖️']], m)
}
} catch (e) {
console.error(e)
if (m.sender in confirm) {
let { timeout } = confirm[m.sender]
clearTimeout(timeout)
delete confirm[m.sender]
m.reply('Rejected')
}
// Check if the user is already in a gamble.
if (m.sender in confirm) {
throw 'You are still in a gamble. Please wait until it is finished.'
}

try {
let user = global.db.data.users[m.sender]
let count = (args[0] && number(parseInt(args[0])) ? Math.max(parseInt(args[0]), 1) : /all/i.test(args[0]) ? Math.floor(user.money) : 1) * 1

// Limiting the maximum bet amount to 10000.
if (count > 10000) {
count = 10000
}

if (user.money < count) {
return m.reply('💹 You do not have enough money for this bet.')
}

if (!(m.sender in confirm)) {
confirm[m.sender] = {
sender: m.sender,
count,
timeout: setTimeout(() => (m.reply('Bet timed out.'), delete confirm[m.sender]), 60000)
}

let txt = `Are you sure you want to place this bet? Respond with 'yes' or 'no'. \n\nBet Amount: ${count} 💹\nYou have 60 seconds to respond.`
return conn.sendMessage(m.chat, { text: txt, quoted: m, contextInfo: { mentionedJid: [m.sender] } });
}
} catch (e) {
console.error(e)
if (m.sender in confirm) {
let { timeout } = confirm[m.sender]
clearTimeout(timeout)
delete confirm[m.sender]
m.reply('Bet cancelled due to an error.')
}
}
}

handler.before = async m => {
if (!(m.sender in confirm)) return
if (m.isBaileys) return
let { timeout, count } = confirm[m.sender]
let user = global.db.data.users[m.sender]
let moneyDulu = user.money * 1
let txt = (m.msg && m.msg.selectedDisplayText ? m.msg.selectedDisplayText : m.text ? m.text : '').toLowerCase()
try {
if (/^(|y(es|a))?$/i.test(txt)) {
let Bot = (Math.ceil(Math.random() * 91)) * 1
let you = (Math.floor(Math.random() * 71)) * 1
let status = 'lost'
if (Bot < you) {
user.money += count * 1
status = 'win'
} else if (Bot > you) {
user.money -= count * 1
} else {
status = 'seri'
user.money += (Math.floor(count / 1.5)) * 1
}
m.reply(`
| *PLAYERS* | *POINT* |
* BOT:* ${Bot}
* YOU:* ${you}
You *${status}*, You ${status == 'win' ? `get *+${count * 2}*` : status == 'lost' ? `loss *-${count * 1}*` : `get *+${Math.floor(count / 1.5)}*`} Money 💹
`.trim())
clearTimeout(timeout)
delete confirm[m.sender]
return !0
} else if (/^(|no)?$/i.test(txt)) {
clearTimeout(timeout)
delete confirm[m.sender]
m.reply('Rejected')
return !0
}

} catch (e) {
clearTimeout(timeout)
delete confirm[m.sender]
if (moneyDulu > (user.money * 1)) user.money = moneyDulu * 1
m.reply('Error while betting (Rejected)')
return !0
} finally {
clearTimeout(timeout)
delete confirm[m.sender]
return !0
if (!(m.sender in confirm)) return
if (m.isBaileys) return

let { timeout, count } = confirm[m.sender]
let user = global.db.data.users[m.sender]
let initialMoney = user.money * 1
let txt = (m.msg && m.msg.selectedDisplayText ? m.msg.selectedDisplayText : m.text ? m.text : '').toLowerCase()

try {
if (/^(|y(es|a))?$/i.test(txt)) {
let botScore = (Math.ceil(Math.random() * 51)) * 1 // Random score for the bot (1 to 51)
let playerScore = (Math.floor(Math.random() * 101)) * 1 // Random score for the player (1 to 100)
let status = 'lost'

if (botScore < playerScore) {
user.money += count * 1
status = 'won'
} else if (botScore > playerScore) {
user.money -= count * 1
} else {
status = 'draw'
user.money += Math.floor(count / 1.5) * 1
}

let result = `
| *Players* | *Points* |
* Bot:* ${botScore}
* You:* ${playerScore}
You *${status}*. Your new balance: ${user.money} 💹
`.trim()

m.reply(result)
clearTimeout(timeout)
delete confirm[m.sender]
return true
} else if (/^(|no)?$/i.test(txt)) {
clearTimeout(timeout)
delete confirm[m.sender]
m.reply('Bet cancelled.')
return true
}

} catch (e) {
clearTimeout(timeout)
delete confirm[m.sender]

// If money was lost due to an error, restore it.
if (initialMoney > user.money) user.money = initialMoney

m.reply('Bet cancelled due to an error.')
return true
} finally {
clearTimeout(timeout)
delete confirm[m.sender]
return true
}
}

handler.help = ['judi [jumlah]']
handler.help = ['bet [amount]']
handler.tags = ['rpg']
handler.command = /^(judi|bet)$/i
handler.command = /^(bet)$/i

export default handler

/**
* Detect if thats number
* @param {Number} x
* Detect if the input is a number
* @param {Number} x
* @returns Boolean
*/
function number(x = 0) {
x = parseInt(x)
return !isNaN(x) && typeof x == 'number'
x = parseInt(x)
return !isNaN(x) && typeof x == 'number'
}
72 changes: 20 additions & 52 deletions plugins/econ-craft.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
let { MessageType } = (await import('@adiwajshing/baileys')).default

let handler = async (m, { conn, command, args, usedPrefix, DevMode }) => {
let type = (args[0] || '').toLowerCase()
let _type = (args[0] || '').toLowerCase()
Expand Down Expand Up @@ -41,104 +39,74 @@ let lgocraft = `
〉6 Diamond
〉10k Money
`
const sections = [
{
title: "CRAFT A TOOLS",
rows: [
{title: "SWORD ⚔️", rowId: ".craft sword", description: "Crafting A Sword"},
{title: "PICKAXE ⛏️", rowId: ".craft pickaxe", description: "Crafting A Pickaxe"},
{title: "FISHINGROD 🎣", rowId: ".craft fishingrod", description: "Crafting A Fishingrod"},
{title: "ARMOR 🥼", rowId: ".craft armor", description: "Crafting A Armor"},
{title: "ATM 💳", rowId: ".craft atm", description: "Crafting A Atm (but that's ilegal)"},
]
},
]

const listMessage = {
text: caption,
footer: wm,
title: lgocraft,
buttonText: " C R A F T ",
sections
}

try {
if (/craft|Crafting/i.test(command)) {
const count = args[1] && args[1].length > 0 ? Math.min(99999999, Math.max(parseInt(args[1]), 1)) : !args[1] || args.length < 3 ? 1 : Math.min(1, count)
switch (type) {
case 'pickaxe':
if (user.pickaxe > 0) return m.reply('You already have this')
if(user.rock < 5 || user.wood < 10 || user.iron < 5 || user.string < 20) return m.reply(`Not enough goods!\nTo make a pickaxe. you need : \n10 wood🪵 \n5 iron⛓\n20 String🕸️\n5 rock1 🪨`)
if(user.rock < 5 || user.wood < 10 || user.iron < 5 || user.string < 20) return conn.sendMessage(m.chat, { text: `Not enough goods!\nTo make a pickaxe. you need : \n10 wood🪵 \n5 iron⛓\n20 String🕸️\n5 rock1 🪨`, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.db.data.users[m.sender].wood -= 10
global.db.data.users[m.sender].iron -= 5
user.rock -= 5
global.db.data.users[m.sender].string -= 20
global.db.data.users[m.sender].pickaxe += 1
user.pickaxedurability = 40
m.reply("Sucess making 1 pickaxe 🔨")
conn.sendMessage(m.chat, { text: "Sucess making 1 pickaxe 🔨", quoted: m, contextInfo: { mentionedJid: [m.sender] } })
break
case 'sword':
if (user.sword > 0) return m.reply(' You already have this')
if(user.wood < 10 || user.iron < 15) return m.reply(`Not enough goods!\nTo make swords. you need :\n10 Wood🪵\n15 iron⛓️`)
if(user.wood < 10 || user.iron < 15) return conn.sendMessage(m.chat, { text: `Not enough goods!\nTo make swords. you need :\n10 Wood🪵\n15 iron⛓️`, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.db.data.users[m.sender].wood -= 10
global.db.data.users[m.sender].iron -= 15
global.db.data.users[m.sender].sword += 1
user.sworddurability = 40
m.reply("Sucess making 1 sword 🗡️")
conn.sendMessage(m.chat, { text: "Sucess making 1 sword 🗡️", quoted: m, contextInfo: { mentionedJid: [m.sender] } })
break
case 'fishingrod':
if (user.fishingrod > 0) return m.reply('You already have this')
if(user.wood < 20 || user.iron < 5 || user.string < 20) return m.reply(`Not enough goods!\nTo make a fishing rod. you need :\n10 wood🪵\n5 iron⛓\n20 String🕸️`)
if(user.wood < 20 || user.iron < 5 || user.string < 20) return conn.sendMessage(m.chat, { text: `Not enough goods!\nTo make a fishing rod. you need :\n10 wood🪵\n5 iron⛓\n20 String🕸️`, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.db.data.users[m.sender].wood -= 10
global.db.data.users[m.sender].iron -= 2
global.db.data.users[m.sender].string -= 20
global.db.data.users[m.sender].fishingrod += 1
user.fishingroddurability = 40
m.reply("Sucess making 1 fishing rod 🎣")
conn.sendMessage(m.chat, { text: "Sucess making 1 fishing rod 🎣", quoted: m, contextInfo: { mentionedJid: [m.sender] } })
break
case 'armor':
if (user.armor > 0) return m.reply(' already have this')
if(user.iron < 30 || user.emerald < 1 || user.diamond < 5) return m.reply(`Not enough goods!\nto make armor. you need :\n30 Iron ⛓️\n1 Emerald ❇️\n5 Diamond 💎`)
if(user.iron < 15 || user.emerald < 1 || user.diamond < 5) return conn.sendMessage(m.chat, { text: `Not enough goods!\nto make armor. you need :\n30 Iron ⛓️\n1 Emerald ❇️\n5 Diamond 💎`, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.db.data.users[m.sender].emerald -= 1
global.db.data.users[m.sender].iron -= 30
global.db.data.users[m.sender].iron -= 15
global.db.data.users[m.sender].diamond -= 5
global.db.data.users[m.sender].armor += 1
user.armordurability = 50
m.reply("Sucess making 1 Armor 🥼")
conn.sendMessage(m.chat, { text: "Sucess making 1 Armor 🥼", quoted: m, contextInfo: { mentionedJid: [m.sender] } })
break
case 'atm':
if (user.atm > 0) return m.reply('you already have this')
if(user.emerald < 3 || user.money < 10000 || user.diamond < 6) return m.reply(`not enough goods!\nto make atm.you need :\n10k Money 💹\n3 Emerald ❇️\n6 Diamond 💎`)
if(user.emerald < 3 || user.money < 10000 || user.diamond < 6) return conn.sendMessage(m.chat, { text: `not enough goods!\nto make atm.you need :\n10k Money 💹\n3 Emerald ❇️\n6 Diamond 💎`, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.db.data.users[m.sender].emerald -= 3
global.db.data.users[m.sender].money -= 10000
global.db.data.users[m.sender].diamond -= 6
global.db.data.users[m.sender].atm += 1
global.db.data.users[m.sender].fullatm = 5000000
m.reply("Sucess making 1 Atm 💳")
conn.sendMessage(m.chat, { text: "Sucess making 1 atm 💳", quoted: m, contextInfo: { mentionedJid: [m.sender] } })
break

default:
return await conn.sendMessage(m.chat, listMessage)
default:
return conn.sendMessage(m.chat, { text: lgocraft + caption, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
}
} else if (/enchant|enchan/i.test(command)) {
const count = args[2] && args[2].length > 0 ? Math.min(99999999, Math.max(parseInt(args[2]), 1)) : !args[2] || args.length < 4 ? 1 :Math.min(1, count)
switch (_type) {
case 't':
break
case '':
break

default:
return conn.sendButton( m.chat, caption, wm, null, [`⋮☰ Menu`, `.menu`], m)
}
} catch (e) {
conn.reply(m.chat, 'Sorry, there was an error running the command!', m)
if (DevMode) {
m.reply(`*Error:* ${util.format(e)}`)
}
} catch (err) {
m.reply("Error\n\n\n" + err.stack)
}
}

handler.help = ['craft']
handler.help = ['crafting']
handler.tags = ['rpg']
handler.command = /^(craft|crafting|chant)/i
handler.command = /^(craft)$/i


export default handler
8 changes: 4 additions & 4 deletions plugins/econ-dungeon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let handler = async(m, { conn, usedPrefix, command, text }) => {
buttons: buttons,
headerType: 1
}
return conn.reply(m.chat, lmao, false, { quoted: m} )// nak durung menuhi syarat
return conn.reply(m.chat, lmao, false, { quoted: m} )
}
global.dungeon = global.dungeon ? global.dungeon : {}
if (Object.values(global.dungeon).find(room => room.id.startsWith('dungeon') && [room.game.player1, room.game.player2, room.game.player3, room.game.player4].includes(m.sender))) return m.reply('You are still in the Dungeon') // nek iseh neng njero dungeon
Expand Down Expand Up @@ -67,7 +67,7 @@ let handler = async(m, { conn, usedPrefix, command, text }) => {
buttons: buttons,
headerType: 1
}
conn.sendButton(m.chat, `*${htki} DUNGEON ${htka}*`, lmao, null, ['send', ''], false, {quoted: m})
return conn.reply(m.chat, lmao, false, { quoted: m} )

if (room.game.player1 && room.game.player2 && room.game.player3 && room.game.player4) {

Expand Down Expand Up @@ -354,7 +354,7 @@ let handler = async(m, { conn, usedPrefix, command, text }) => {
buttons: buttons,
headerType: 1
}
conn.sendButton(m.chat, `*DUNGEON*`,lmao, null, ['send', 'Gass..'], false, { quoted: m})
conn.sendMessage(m.chat, { text: lmao, quoted: m, contextInfo: { mentionedJid: [m.sender] } })
global.dungeon[room.id] = room
}
}
Expand Down Expand Up @@ -778,4 +778,4 @@ function data(DATA) {
}
})
return msg
}
}
6 changes: 3 additions & 3 deletions plugins/econ-leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ let handler = async (m, { conn, args, participants }) => {
≡ *𝐋𝐄𝐀𝐃𝐄𝐑𝐁𝐎𝐀𝐑𝐃*
▢ *TOP ${len} XP* 🧬
YOU : *${usersExp.indexOf(m.sender) + 1}* de *${usersExp.length}*
YOU : *${usersExp.indexOf(m.sender) + 1}* from *${usersExp.length}*
${sortedExp.slice(0, len).map(({ jid, exp }, i) => `*${i + 1}.* ${participants.some(p => areJidsSameUser(jid, p.id)) ? `(${conn.getName(jid)}) wa.me/` : '@'}${jid.split`@`[0]} ➭ _*XP ${exp}*_`).join`\n`}
▢ *TOP ${len} DIAMONDS💎*
YOU : *${usersLim.indexOf(m.sender) + 1}* de *${usersLim.length}*
YOU : *${usersLim.indexOf(m.sender) + 1}* from *${usersLim.length}*
${sortedLim.slice(0, len).map(({ jid, diamond }, i) => `*${i + 1}.* ${participants.some(p => areJidsSameUser(jid, p.id)) ? `(${conn.getName(jid)}) wa.me/` : '@'}${jid.split`@`[0]} ➭ _*Diamonds ${diamond}*_`).join`\n`}
▢ *TOP ${len} LEVEL* ⬆️
YOU : *${usersLevel.indexOf(m.sender) + 1}* de *${usersLevel.length}*
YOU : *${usersLevel.indexOf(m.sender) + 1}* from *${usersLevel.length}*
${sortedLevel.slice(0, len).map(({ jid, level }, i) => `*${i + 1}.* ${participants.some(p => areJidsSameUser(jid, p.id)) ? `(${conn.getName(jid)}) wa.me/` : '@'}${jid.split`@`[0]} ➭ _*Level ${level}*_`).join`\n`}
`.trim()
Expand Down
Loading

0 comments on commit 6d70b28

Please sign in to comment.