diff --git a/bot/commands/admin/sendMessage.js b/bot/commands/admin/sendMessage.js index 54acc45..56e5746 100644 --- a/bot/commands/admin/sendMessage.js +++ b/bot/commands/admin/sendMessage.js @@ -1,8 +1,9 @@ import { INITIAL_SESSION } from '../../constants/index.js' +import { db } from '../../db/index.js' // TODO: сделать цикл и возможность отправки сообщений группам пользователей export const sendMessage = bot => { bot.onText(/^\/msg+/ig, async msg => { - if (msg?.chat?.id == process.env.NOTIF_GROUP) { + if (msg?.chat?.id === process.env.NOTIF_GROUP) { const text = msg.text.split('&&') const { id: chatId } = msg.chat const options = { @@ -10,11 +11,26 @@ export const sendMessage = bot => { } msg['ctx'] = INITIAL_SESSION try { - await bot.sendMessage( - text[1], - `🤖\n${text[2]}`, - options - ) + if (text[1] === 'all') { + const subscribers = await db.subscriber.findAll({ + subQuery: false, + order: [['createdAt', 'DESC']] + }) + + if (msg['reply_to_message'].photo.length) { + console.log('msg[\'reply_to_message\'].photo', msg['reply_to_message'].photo) + // отправить всем пользователям сообщение с картинкой + // subscribers.map(user => bot.sendPhoto(user['chat_id'])) + } else { + subscribers.map(user => bot.sendMessage(user.chat_id, '🔮')) + } + } else { + await bot.sendMessage( + text[1], + `🤖\n${text[2]}`, + options + ) + } } catch (error) { await bot.sendMessage(chatId, `${error.message}`, options) }