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

33 lines
1.2 KiB
JavaScript
Raw 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 {
rarecars,
simplecars,
UserModel,
PropertyModel
} = global.config
const {
spaces
} = global.utils
module.exports = async (ctx) => {
let data = ctx.update.callback_query.data;
let user = await UserModel.findByPk(ctx.from.id)
let property = await PropertyModel.findByPk(ctx.from.id)
if(user.money < 500000) return ctx.telegram.answerCbQuery(ctx.callbackQuery.id, `Открытие контейнера стоит ₽500.000`, {show_alert: true})
if(property.car1.name) return ctx.telegram.answerCbQuery(ctx.callbackQuery.id, `У вас уже есть автомобиль\nПродайте текущий автомобиль: /sell car`, {show_alert: true})
user.money -= 500000
let userWin = null
switch(data){
case `container_7`:
userWin = rarecars.random()
break;
default:
userWin = simplecars.random()
break;
}
property.car1 = userWin
property.car1.health = 100
user.save()
property.save()
ctx.deleteMessage()
return await ctx.sendPhoto(userWin.image, { caption: `В контейнере была: ${userWin.name} стоимостью ₽${spaces(userWin.price)}`})
}