CampFirePlay/commands/organization/invite.js
Degradin baa0b5f3a9 global refactoring
Все переведено в модули
2023-10-08 23:43:12 +03:00

38 lines
1.5 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 {
Telegraf,
Markup
} = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
const {
UserModel,
BusinessModel
} = require('/workspace/degradin/Dev/Telegram/CampFire Play/config')
module.exports = async (ctx) => {
ctx.args = ctx.update.message.text.split(' ')
if (!ctx.args[1]) return ctx.reply(`/invite [Nick]`)
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.users.length >= 5) return await ctx.reply(`📛 Достигнуто максимальное количество сотрудников в организации.`)
let invited = await UserModel.findOne({
where: {
username: ctx.args[1]
}
});
await bot.telegram.sendMessage(invited.telegram_id, '⤵️ Приглашение', Markup
.inlineKeyboard([
[{
text: `Принять`,
callback_data: `{"type": "business_invite_accept", "invitor": "${user.telegram_id}"}`
}, {
text: `Отклонить`,
callback_data: `{"type": "business_invite_refuse", "invitor": "${user.telegram_id}"}`
}]
]).oneTime())
return await ctx.reply(`Приглашение отправлено.`)
}