Added chatinfo + typo fixes + whois update

This commit is contained in:
Lucas Gabriel 2024-05-25 12:37:34 -03:00
parent 318dce8e0b
commit 6d1a1ae745
No known key found for this signature in database
GPG Key ID: D9B075FC6DC93985
3 changed files with 32 additions and 4 deletions

28
src/commands/chatinfo.js Normal file
View File

@ -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}`);
}

View File

@ -1,4 +1,3 @@
// start command handler
module.exports = function(bot, msg) { module.exports = function(bot, msg) {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const userName = msg.from.first_name; 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!` 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) 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}`) console.log(`INFO: /start executed by ${userName}, ${userId}`)
} }

View File

@ -5,6 +5,7 @@ module.exports = function(bot, msg) {
const userHandle = msg.from.username; const userHandle = msg.from.username;
const isBot = msg.from.is_bot; const isBot = msg.from.is_bot;
const userPremium = msg.from.is_premium; const userPremium = msg.from.is_premium;
const userLang = msg.from.language_code;
let userPremiumOutput = ""; let userPremiumOutput = "";
if (userPremium) { if (userPremium) {
@ -13,9 +14,9 @@ module.exports = function(bot, msg) {
userPremiumOutput = "You don't have a Telegram Premium subscription."; 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) 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}`) console.log(`INFO: /whois executed by ${userName}, ${userId}`)
} }