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

24 lines
926 B
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
} = require('telegraf')
const bot = new Telegraf(process.env.BOT_TOKEN)
const {
UserModel,
BusinessModel
} = require('/dev/Telegram/CampFireGameBot/config')
module.exports = async (ctx) => {
if (!ctx.args[1]) return ctx.reply(`Не указан аргумент.`)
let business = await BusinessModel.findOne({
where: {
owner: ctx.from.id.toString()
}
})
if (business === null) return await ctx.reply(`У вас нет организации.`)
for (i = 0; i < business.users.length; i++) {
user = await UserModel.findByPk(business.users[i])
await bot.telegram.sendMessage(user.telegram_id, `Директор организации сообщает:\n ${ctx.payload}`)
}
console.log(`Директор организации сообщает:\n ${ctx.payload}`)
return await ctx.reply(`Сообщение отправлено.`)
}