From 4fe93cac7c8aa8d62c84dd213620a324f1778a5f Mon Sep 17 00:00:00 2001 From: Vufer Date: Mon, 30 Jun 2025 21:42:55 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=87=D0=B0=D1=82=D0=B0=20=D0=B2=20=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D1=8E.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit вывод списка чатов в виде id. --- bot.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bot.js b/bot.js index 25f097b..a61ddc1 100644 --- a/bot.js +++ b/bot.js @@ -39,6 +39,13 @@ class TelegramHistoryBot { return false } } + getUniqueChatIds() { + const ids = new Set(); + for (const msg of this.history) { + ids.add(msg.chat_id); + } + return Array.from(ids); + } async init() { try { @@ -126,6 +133,15 @@ class TelegramHistoryBot { }); + this.bot.command('getchats', 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 chatIds = this.getUniqueChatIds(); + await ctx.reply(JSON.stringify(chatIds)) + }); // Команды суммаризации - должны быть ДО обработки обычных сообщений // this.bot.command('summary_day', async (ctx) => { // // if (!this.isAdmin(ctx)) { @@ -214,6 +230,7 @@ class TelegramHistoryBot { id: this.generateUniqueId(), telegram_message_id: msg.message_id, chat_id: msg.chat.id, + chat_title: msg.chat.title || null, user_id: msg.from.id, username: msg.from.username || null, first_name: msg.from.first_name || null,