Modulate bot with some tweaks
This commit is contained in:
parent
92b6afe340
commit
c67df9f865
5 changed files with 33 additions and 15 deletions
24
src/main.js
Normal file
24
src/main.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
const TelegramBot = require('node-telegram-bot-api');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const token = process.env.TGBOT_TOKEN; // config.env
|
||||
const bot = new TelegramBot(token, { polling: true });
|
||||
|
||||
const commandsPath = path.join(__dirname, 'commands')
|
||||
const commandHandlers = {};
|
||||
|
||||
// load all commands
|
||||
fs.readdirSync(commandsPath).forEach(file => {
|
||||
const command = `/${path.parse(file).name}`;
|
||||
const handler = require(path.join(commandsPath,file));
|
||||
commandHandlers[command] = handler;
|
||||
})
|
||||
|
||||
bot.on('message', (msg) => {
|
||||
const messageText = msg.text;
|
||||
if (commandHandlers[messageText]) {
|
||||
commandHandlers[messageText](bot, msg);
|
||||
}
|
||||
});
|
||||
|
||||
console.log("INFO: Lynx started.")
|
Loading…
Add table
Add a link
Reference in a new issue