2024-05-24 18:39:12 -03:00
|
|
|
const TelegramBot = require('node-telegram-bot-api');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2024-06-02 01:38:25 -03:00
|
|
|
const logMessage = require('./logger');
|
2024-06-02 03:36:04 -03:00
|
|
|
const { isBlocked } = require('./blocklist');
|
2024-06-02 01:38:25 -03:00
|
|
|
const token = process.env.TGBOT_TOKEN;
|
2024-05-24 18:39:12 -03:00
|
|
|
const bot = new TelegramBot(token, { polling: true });
|
|
|
|
|
2024-06-02 01:38:25 -03:00
|
|
|
const commandsPath = path.join(__dirname, 'commands');
|
2024-05-24 18:39:12 -03:00
|
|
|
const commandHandlers = {};
|
|
|
|
|
|
|
|
fs.readdirSync(commandsPath).forEach(file => {
|
|
|
|
const command = `/${path.parse(file).name}`;
|
2024-06-02 01:38:25 -03:00
|
|
|
const handler = require(path.join(commandsPath, file));
|
2024-05-24 18:39:12 -03:00
|
|
|
commandHandlers[command] = handler;
|
2024-06-02 01:38:25 -03:00
|
|
|
});
|
2024-05-24 18:39:12 -03:00
|
|
|
|
|
|
|
bot.on('message', (msg) => {
|
2024-06-02 01:48:19 -03:00
|
|
|
const userId = msg.from.id;
|
|
|
|
|
|
|
|
if (isBlocked(userId)) {
|
|
|
|
console.log(`WARN: Blocked user ${userId} tried to access the bot.`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-24 18:39:12 -03:00
|
|
|
const messageText = msg.text;
|
|
|
|
if (commandHandlers[messageText]) {
|
|
|
|
commandHandlers[messageText](bot, msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-05-31 17:40:29 -03:00
|
|
|
bot.on('polling_error', (error) => {
|
2024-06-02 01:48:19 -03:00
|
|
|
console.error('WARN: Polling error:', error);
|
2024-05-31 17:40:29 -03:00
|
|
|
});
|
|
|
|
|
2024-06-02 01:38:25 -03:00
|
|
|
const date = new Date().toString();
|
|
|
|
console.log(`INFO: Lynx started\n`);
|