-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (31 loc) · 933 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const TelegramBot = require("node-telegram-bot-api")
let { token } = require("./config")
const bot = new TelegramBot(token, { polling: true } )
const fs = require("fs")
bot.commands = new Map()
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
bot.onText(/^\/(\w+)(?:@[\w-]+)?(?:\s+(.*))?$/, async (msg, match) => {
const chat = msg.chat.id
const command = bot.commands.get(match[1])
if(!command) return;
msg.args = match[2] ? match[2].split(/\s+/) : []
try {
command.execute(bot, msg, chat)
} catch (error) {
console.log(error)
}
})
//Express
const express = require("express")
const app = express()
app.get("/", (req,res) =>{
res.send("My Awesome Bot online")
res.status(200)
})
app.listen(8000, ()=>{
console.log("Bot is ready!")
})