CampFirePlay/commands/casino/slots.js
2024-12-21 20:01:15 +03:00

68 lines
1.9 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const {
slots,
UserModel,
WorldModel
} = global.config
const {
spaces,
getSlot,
giveExp,
setCooldown
} = global.utils
module.exports = async (ctx) => {
let data = ctx.update.callback_query.data;
let bet = 1000
switch(data){
case `slots1000`:
bet = 1000
break;
case `slots5000`:
bet = 5000
break;
case `slots25000`:
bet = 25000
break;
case `slots50000`:
bet = 50000
break;
case `slots100000`:
bet = 100000
break;
}
let user = await UserModel.findByPk(ctx.from.id)
let timer = user.slottime
let cooldown = setCooldown(user, 10, timer)
if (user.slottime > cooldown.currentTime) return ctx.reply(`📛 Слоты будут доступны через пару секунд`);
if (user.money < bet) return ctx.reply(`Недостаточно средств.`)
user.slottime = cooldown.endTime
let world = await WorldModel.findByPk(1)
let result = await ctx.replyWithDice({emoji: `🎰`})
let slot = slots[result.dice.value]
let win = getSlot(result)
console.log(user.username + `: Win: x` + win)
user.money -= bet
world.balance += bet
if(win > 4){
user.world -= bet*win
user.money += bet*win
user.save()
world.save()
return setTimeout(() => {
ctx.reply(` Вы выиграли ₽${spaces(bet*win)}`)
}, 1700);
}
if(win > 0 && win <= 4){
await giveExp(user, win*2)
return setTimeout(() => {
ctx.reply(` Вы выиграли ${win*2} опыта.`)
}, 1700);
}
if(win == 0){
return setTimeout(() => {
world.save()
user.save()
ctx.reply(` Вы проиграли ₽${spaces(bet)}.`)
}, 1700);
}
}