-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (60 loc) · 1.4 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require('dotenv').config()
require('./helpers/additionalInit')
const connectToDb = require('./db/connect')
const CallbackQueryController = require('./Controllers/CallbackQueryController')
const MessageEventController = require('./Controllers/MessageEventController')
const StartController = require('./Controllers/StartController')
const {
info: infoLogger,
error: errorLogger,
} = require('./services/loggerService')
/**
*
* BOT CONNECTION
*
*/
const bot = require('./modules/getBot')()
/**
*
* MONGODB ATLAS CONNECTION
*
*/
connectToDb()
/**
*
* OnClick /start
*
*/
bot.onText(/^\/start$/, StartController)
/**
*
* OnUserSendMessage message
*
*/
bot.on('message', MessageEventController)
/**
*
* OnClick inline buttons
*
*/
bot.on('callback_query', CallbackQueryController)
const { pid } = process
process
.on('SIGINT', () => {
infoLogger(`${__filename}\n${__line}\nProcess ${pid} stopped manually`)
process.exit(0)
})
.on('SIGTERM', () => {
infoLogger(`${__filename}\n${__line}\nProcess ${pid} stopped`)
process.exit(0)
})
.on('unhandledRejection', reason => {
errorLogger(
`${__filename}\n${__line}\nUnhandled rejection\n${reason.stack.toString()}`
)
})
.on('uncaughtException', err => {
errorLogger(
`${__filename} ${__line} Uncaught exception\n${err.stack.toString()}`
)
})