From 11801add49e36944f98474a6665a52a754714dda Mon Sep 17 00:00:00 2001 From: Vufer Date: Mon, 30 Jun 2025 22:10:09 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20/broadcast=20=D1=80=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D1=8B=D0=BB=D0=BA=D0=B0=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=20=D0=B2=D1=81=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=87=D0=B0=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bot.js b/bot.js index 0e08003..29a3475 100644 --- a/bot.js +++ b/bot.js @@ -155,6 +155,28 @@ class TelegramHistoryBot { .join('\n'); await ctx.reply(message) }); + this.bot.command('broadcast', async (ctx) => { + if (ctx.message.chat.id!==Number(process.env.ADMIN_CHAT_ID)) { + logger.warn(JSON.stringify(ctx.message)) + logger.warn('Попытка вызова бродкаста из стороннего чата. Пользователь ' + JSON.stringify(ctx.message.from)) + return + } + const fullText = ctx.message.text || ''; + const text = fullText.replace(/^\/broadcast\s*/, '').trim(); + if (!text) { + return ctx.reply('❗️ Пожалуйста, укажите текст для рассылки после команды /broadcast'); + } + logger.info('📊 Получена команда /broadcast с запросом:' + text) + const chatList= this.getUniqueChatIds() + for (const chat of chatList) { + try { + await this.bot.telegram.sendMessage(chat.chat_id, text); + logger.info(`✅ Сообщение отправлено в чат ${chat.title} (${chat.chat_id})`); + } catch (error) { + logger.error(`❌ Ошибка при отправке в чат ${chat.title} (${chat.chat_id}):`, error); + } + } + }) // Команды суммаризации - должны быть ДО обработки обычных сообщений // this.bot.command('summary_day', async (ctx) => { // // if (!this.isAdmin(ctx)) {