From e0380eeebf1d14b252843923b890800e54ce945c Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Sat, 25 May 2024 12:56:54 -0300 Subject: [PATCH] PM check in chatinfo --- src/commands/chatinfo.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/chatinfo.js b/src/commands/chatinfo.js index 7e39584..1f42dd6 100644 --- a/src/commands/chatinfo.js +++ b/src/commands/chatinfo.js @@ -1,12 +1,13 @@ module.exports = function(bot, msg) { const chatId = msg.chat.id; - const chatName = msg.chat.title; const userName = msg.from.first_name; const userId = msg.from.id; + const chatName = msg.chat.title; const chatHandle = msg.chat.username; const isForum = msg.chat.is_forum; - let isForumOutput = ""; + let chatNameOutput = ""; let chatHandleOutput = ""; + let isForumOutput = ""; if (isForum) { isForumOutput = "This chat is a forum (has topics enabled)"; @@ -20,7 +21,13 @@ module.exports = function(bot, msg) { chatHandleOutput = `Chat handle: none (private group)`; } - const message = `Chat name: ${chatName}\n${chatHandleOutput}\nChat ID: ${chatId}\n\n${isForumOutput}`; + if (chatName) { + chatNameOutput = `Chat name: ${chatName}\n${chatHandleOutput}\nChat ID: ${chatId}\n\n${isForumOutput}`; + } else { + chatNameOutput = `Whoops!\nThis command doesn't work in PM.` + } + + const message = chatNameOutput; bot.sendMessage(chatId, message) .catch(error => console.error('ERROR: Message cannot be sent:', error));