Reformulation of bot structure

This commit is contained in:
Lucas Gabriel 2024-06-02 14:55:44 +00:00
parent 4b9ed6d2c0
commit 2f65126319
15 changed files with 2 additions and 2 deletions

33
commands/chatinfo.js Normal file
View file

@ -0,0 +1,33 @@
module.exports = function(bot, msg) {
const chatId = msg.chat.id;
const chatName = msg.chat.title;
const chatHandle = msg.chat.username;
const isForum = msg.chat.is_forum;
let chatNameOutput = "";
let chatHandleOutput = "";
let isForumOutput = "";
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)`;
}
// if chatName returns undefined, the chat is not a group or channel
if (chatName) {
chatNameOutput = `*Chat name:* ${chatName}\n${chatHandleOutput}\n*Chat ID:* ${chatId}\n\n${isForumOutput}`;
} else {
chatNameOutput = "Whoops!\nThis command doesn't work in PM.";
}
const message = chatNameOutput;
bot.sendMessage(chatId, message, { parse_mode: 'Markdown' })
.catch(error => console.error('WARN: Message cannot be sent: ', error));
}