34 lines
1.4 KiB
JavaScript
34 lines
1.4 KiB
JavaScript
const {
|
||
UserModel,
|
||
BusinessModel
|
||
} = global.config
|
||
|
||
module.exports = async (ctx) => {
|
||
ctx.args = ctx.update.message.text.split(' ')
|
||
let user = await UserModel.findByPk(ctx.from.id)
|
||
if (user.business.id == 0) return await ctx.reply(`Вы не владеете организацией.`)
|
||
let business = await BusinessModel.findOne({
|
||
where: {
|
||
owner: ctx.from.id.toString()
|
||
}
|
||
})
|
||
if (business === null) return await ctx.reply(`У вас нет организации.`)
|
||
if (!ctx.args[1] || !ctx.args[2]) return ctx.reply(`Не указан аргумент.`)
|
||
if (!Number(ctx.args[2])) return ctx.reply(`Процент должен быть числом от 1 до 100.`)
|
||
if (ctx.args[2] < 1 || ctx.args[2] > 100) return ctx.reply(`Минимальный процент 1 | Максимальный процент 100.`)
|
||
ctx.args[1] = ctx.args[1]
|
||
console.log(ctx.args)
|
||
let change = await UserModel.findOne({
|
||
where: {
|
||
username: ctx.args[1]
|
||
}
|
||
})
|
||
if (change === null) return await ctx.reply(`Нет такого игрока.`)
|
||
change.business = {
|
||
id: change.business.id,
|
||
checks: change.business.checks,
|
||
percent: ctx.args[2]
|
||
}
|
||
change.save()
|
||
return await ctx.reply(`Участнику ${change.username} установлен процент ${ctx.args[2]}`)
|
||
} |