From c0cda72db5f668836b4e8742c2e0a192f2dfaf19 Mon Sep 17 00:00:00 2001 From: Vufer Date: Mon, 30 Jun 2025 20:41:54 +0300 Subject: [PATCH] =?UTF-8?q?fix(bot):=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83?= =?UTF-8?q?=20isAdmin=20=D0=B0=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Исправлен метод isAdmin на асинхронный с ожиданием результата - Добавлен вывод ошибок в лог при проверке статуса пользователя - В хэндлере команды /summy добавлена проверка прав администратора с удалением сообщения, если пользователь не админ --- bot.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bot.js b/bot.js index e1f4d22..c9d2a51 100644 --- a/bot.js +++ b/bot.js @@ -29,14 +29,16 @@ class TelegramHistoryBot { this.init(); } - isAdmin (ctx, userId = ctx.from.id) { + async isAdmin(ctx, userId = ctx.from.id) { try { - const member = ctx.getChatMember(userId) + const member = await ctx.getChatMember(userId) return ['creator', 'administrator'].includes(member.status) - } catch { + } catch (error) { + logger.error('Ошибка проверки статуса пользователя:', error) return false } } + async init() { try { await this.loadHistory(); @@ -70,6 +72,10 @@ class TelegramHistoryBot { setupHandlers() { this.bot.command('summy', async (ctx) => { + if (!(await this.isAdmin(ctx))) { + await ctx.deleteMessage() + return + } const message = ctx.message.text || ''; const args = message.replace(/^\/summy(@\w+)?\s*/, ''); // удаляет /summy и возможный @botname const trimmed = args.trim(); // удаляет лишние пробелы по краям, если нужно