kowalski/src/main.js

30 lines
833 B
JavaScript
Raw Normal View History

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');
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) => {
const messageText = msg.text;
if (commandHandlers[messageText]) {
commandHandlers[messageText](bot, msg);
}
});
2024-05-31 17:40:29 -03:00
bot.on('polling_error', (error) => {
console.error('Polling error:', error);
});
2024-06-02 01:38:25 -03:00
const date = new Date().toString();
console.log(`INFO: Lynx started\n`);