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

42 lines
1.3 KiB
JavaScript

const {
Telegraf,
Markup
} = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
const {
UserModel,
BusinessModel
} = global.config
module.exports = async (ctx) => {
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){
business = await BusinessModel.findOne({
where: {
owner: user.business.id
}
})
await ctx.reply(`Подтвердите в личных сообщениях.`)
return await bot.telegram.sendMessage(ctx.from.id, `🏭 Вы действительно хотите покинуть ${business.name}`, Markup.inlineKeyboard([
[{
text: `Да`,
callback_data: "user_leave_business"
}, {
text: `Нет`,
callback_data: "cancel"
}]
])
.oneTime()
.resize()
)
}
if (business.owner == ctx.from.id){
return await ctx.reply(`Вы не можете покинуть свою организацию.`)
}
}