From 6d1a1ae745c373a436e8af2b4a47a30e1a0b1a98 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Sat, 25 May 2024 12:37:34 -0300 Subject: [PATCH] Added chatinfo + typo fixes + whois update --- src/commands/chatinfo.js | 28 ++++++++++++++++++++++++++++ src/commands/start.js | 3 +-- src/commands/whois.js | 5 +++-- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/commands/chatinfo.js diff --git a/src/commands/chatinfo.js b/src/commands/chatinfo.js new file mode 100644 index 0000000..7e39584 --- /dev/null +++ b/src/commands/chatinfo.js @@ -0,0 +1,28 @@ +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 chatHandle = msg.chat.username; + const isForum = msg.chat.is_forum; + let isForumOutput = ""; + let chatHandleOutput = ""; + + if (isForum) { + isForumOutput = "This chat is a forum (has topics enabled)"; + } else { + isForumOutput = "This chat is not a forum (doesn't have topics enabled)"; + } + + if (chatHandle) { + chatHandleOutput = `Chat handle: @${chatHandle}`; + } else { + chatHandleOutput = `Chat handle: none (private group)`; + } + + const message = `Chat name: ${chatName}\n${chatHandleOutput}\nChat ID: ${chatId}\n\n${isForumOutput}`; + + bot.sendMessage(chatId, message) + .catch(error => console.error('ERROR: Message cannot be sent:', error)); + console.log(`INFO: /chatinfo executed by ${userName}, ${userId}`); +} \ No newline at end of file diff --git a/src/commands/start.js b/src/commands/start.js index bd48a28..a3c6a98 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -1,4 +1,3 @@ -// start command handler module.exports = function(bot, msg) { const chatId = msg.chat.id; const userName = msg.from.first_name; @@ -7,6 +6,6 @@ module.exports = function(bot, msg) { const message = `Hello! I am Lynx!\nI was made with love by Lucas Gabriel (lucmsilva)!\n\nSee /help for the bot commands!` bot.sendMessage(chatId, message) - .catch(error => console.error('ERROR: Message cannot be send:', error)); + .catch(error => console.error('ERROR: Message cannot be sent:', error)); console.log(`INFO: /start executed by ${userName}, ${userId}`) } \ No newline at end of file diff --git a/src/commands/whois.js b/src/commands/whois.js index 027771d..b043010 100644 --- a/src/commands/whois.js +++ b/src/commands/whois.js @@ -5,6 +5,7 @@ module.exports = function(bot, msg) { const userHandle = msg.from.username; const isBot = msg.from.is_bot; const userPremium = msg.from.is_premium; + const userLang = msg.from.language_code; let userPremiumOutput = ""; if (userPremium) { @@ -13,9 +14,9 @@ module.exports = function(bot, msg) { userPremiumOutput = "You don't have a Telegram Premium subscription."; } - const message = `Your name is: ${userName}\nYour username is: ${userHandle}\nYour ID is: ${userId}\nYou are a bot: ${isBot}\n\n${userPremiumOutput}`; + const message = `Your name is: ${userName}\nYour username is: @${userHandle}\nYour ID is: ${userId}\nYou are a bot: ${isBot}\nYour language: ${userLang}\n\n${userPremiumOutput}`; bot.sendMessage(chatId, message) - .catch(error => console.error('ERROR: Message cannot be send:', error)); + .catch(error => console.error('ERROR: Message cannot be sent:', error)); console.log(`INFO: /whois executed by ${userName}, ${userId}`) } \ No newline at end of file