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,