From 977291d6395852c5f09bddf52c76de044052a244 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel <90426410+lucmsilva651@users.noreply.github.com> Date: Fri, 24 May 2024 20:57:44 -0300 Subject: [PATCH] Fixed whois + added help --- src/commands/help.js | 15 +++++++++++++++ src/commands/whois.js | 14 ++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/commands/help.js diff --git a/src/commands/help.js b/src/commands/help.js new file mode 100644 index 0000000..e2b1fca --- /dev/null +++ b/src/commands/help.js @@ -0,0 +1,15 @@ +module.exports = function(bot, msg) { + const chatId = msg.chat.id; + const userName = msg.from.first_name; + const userId = msg.from.id; + + const message = `Hi! I am Lynx!\nI am a simple bot made entirely from scratch in Node.js by Lucas Gabriel (lucmsilva).\n\nSome commands to test: + - /start: start the bot + - /help: send this message + - /whois: send some information about yourself\n\nSee my source code in: + https://github.com/lucmsilva651/lynx.\n\nThanks to all users, testers, contributors, and others. Without you, perhaps this bot wouldn't be possible.`; + + bot.sendMessage(chatId, message) + .catch(error => console.error('ERROR: Message cannot be send:', error)); + console.log(`INFO: /help executed by ${userName}, ${userId}`); +} diff --git a/src/commands/whois.js b/src/commands/whois.js index ebe0d84..027771d 100644 --- a/src/commands/whois.js +++ b/src/commands/whois.js @@ -5,14 +5,16 @@ module.exports = function(bot, msg) { const userHandle = msg.from.username; const isBot = msg.from.is_bot; const userPremium = msg.from.is_premium; - const userPremiumOutput = ""; - - if (userPremium == "true") { - const userPremiumOutput = "\n\nYou have a Telegram Premium subscription."; + let userPremiumOutput = ""; + + if (userPremium) { + userPremiumOutput = "You have a Telegram Premium subscription."; + } else { + 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}` + userPremiumOutput; - + const message = `Your name is: ${userName}\nYour username is: ${userHandle}\nYour ID is: ${userId}\nYou are a bot: ${isBot}\n\n${userPremiumOutput}`; + bot.sendMessage(chatId, message) .catch(error => console.error('ERROR: Message cannot be send:', error)); console.log(`INFO: /whois executed by ${userName}, ${userId}`)