From 8d478a5d8babe06fd4eb7dc5c12bb68b770cc36f Mon Sep 17 00:00:00 2001 From: GramingFoxTeam Date: Fri, 18 Nov 2022 21:30:34 +0300 Subject: [PATCH] fix(telegram-bot): check for admin first --- bots/telegram/commands/train.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bots/telegram/commands/train.js b/bots/telegram/commands/train.js index a567bcb..851fdc8 100644 --- a/bots/telegram/commands/train.js +++ b/bots/telegram/commands/train.js @@ -1,6 +1,15 @@ export default { command: /\/train/, async execute(bot, config, msg) { + const admins = await bot.getChatAdministrators(msg.chat.id); + const isAdmin = admins.find((admin) => admin.user.id === msg.from.id); + + if (!isAdmin) + return bot.sendMessage(msg.chat.id, 'You\'re not an admin.', { + message_thread_id: msg.message_thread_id, + reply_to_message_id: msg.message_id + }); + if (msg.reply_to_message.message_id === msg.message_thread_id) return bot.sendMessage(msg.chat.id, 'Please reply to a message!', { message_thread_id: msg.message_thread_id, @@ -37,14 +46,6 @@ export default { } } - const admins = await bot.getChatAdministrators(msg.chat.id); - const isAdmin = admins.find((admin) => admin.user.id === msg.from.id); - - if (!isAdmin) - return bot.sendMessage(msg.chat.id, 'You\'re not an admin.', { - message_thread_id: msg.message_thread_id, - reply_to_message_id: msg.message_id - }); bot.sendMessage( msg.chat.id, 'Please select the corresponding label to train the bot.',