mirror of
https://github.com/abocn/TelegramBot.git
synced 2025-03-11 13:19:57 +00:00
Added message logger
This commit is contained in:
parent
1f1ece9ac2
commit
612a48ca7f
@ -4,7 +4,6 @@ const path = require('path');
|
|||||||
const token = process.env.TGBOT_TOKEN;
|
const token = process.env.TGBOT_TOKEN;
|
||||||
const bot = new TelegramBot(token, { polling: true });
|
const bot = new TelegramBot(token, { polling: true });
|
||||||
|
|
||||||
// import logger and blocklist
|
|
||||||
const logMessage = require('./logger');
|
const logMessage = require('./logger');
|
||||||
const { isBlocked } = require('./blocklist');
|
const { isBlocked } = require('./blocklist');
|
||||||
|
|
||||||
@ -18,17 +17,21 @@ fs.readdirSync(commandsPath).forEach(file => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bot.on('message', (msg) => {
|
bot.on('message', (msg) => {
|
||||||
|
const userName = msg.from.first_name;
|
||||||
const userId = msg.from.id;
|
const userId = msg.from.id;
|
||||||
|
const messageText = msg.text;
|
||||||
|
|
||||||
if (isBlocked(userId)) {
|
if (isBlocked(userId)) {
|
||||||
console.log(`WARN: Blocked user ${userId} tried to access the bot.`);
|
console.log(`WARN: Blocked user ${userName}, ${userId} tried to access the bot with the command/message ${messageText}.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const messageText = msg.text;
|
|
||||||
if (commandHandlers[messageText]) {
|
if (commandHandlers[messageText]) {
|
||||||
commandHandlers[messageText](bot, msg);
|
commandHandlers[messageText](bot, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`INFO: User ${userName}, ${userId} sended a message with the content:
|
||||||
|
• ${messageText}\n`)
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('polling_error', (error) => {
|
bot.on('polling_error', (error) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user