CampFirePlay/commands/organization/organizationCreate.js
2024-12-21 09:34:53 +03:00

45 lines
1.6 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 {
UserModel,
WorldModel,
BusinessModel
} = require('/dev/Telegram/CampFireGameBot/config')
module.exports = async (ctx) => {
let user = await UserModel.findByPk(ctx.from.id)
if (user.business.id != 0){
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id.toString()
}
})
}
let business = null
let world = await WorldModel.findByPk(1)
ctx.args = ctx.update.message.text.split(' ')
if (business != null) return await ctx.reply(`У вас уже есть организация.`)
if (!ctx.args[1]) return ctx.reply(`/business [Название организации]`)
if (user.money < 100000) return await ctx.reply(`Регистрация организации стоит ₽100.000`)
if (user.level < 5) return await ctx.reply(`Регистрация организации доступна с 5 уровня.`)
user.money -= 100000
world.balance += 100000
let text = ``
for (i = 1; i < ctx.args.length; i++) {
text += `${ctx.args[i]} `
}
if (business === null) {
BusinessModel.create({
name: text,
owner: user.telegram_id,
balance: 50000,
users: [user.telegram_id]
})
user.business = {
id: user.telegram_id,
checks: 0,
percent: 100
}
} else {}
user.save()
world.save()
return await ctx.reply(`Организация "${text}" успешно создана!\n Регистрация организации в реестре: ₽50.000 \n Капитал: ₽50.000`)
}