-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (25 loc) · 875 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
36
const { Telegraf } = require('telegraf')
const dotenv = require('dotenv');
dotenv.config();
const bot = new Telegraf(process.env.BOT_TOKEN, {username: process.env.BOT_USERNAME})
bot.telegram.getMe().then((botInfo) => {
bot.options.username = botInfo.username
})
bot.start((ctx) => ctx.reply('Seja bem vindo'))
bot.on('message', async ctx => {
const message = ctx.message.text;
const command = message.split(' ').shift() ?? message;
const args = message.split(' ').splice(1);
if(! command.startsWith('!')) {
return;
}
try {
await require(`./commands/${command.substr(1)}`)(ctx, args);
} catch (e) {
// comando não foi encontrado, não precisa de feedback no chat
}
})
bot.launch()
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))