forked from lnp2pBot/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (31 loc) · 1.03 KB
/
app.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
require('dotenv').config();
const { SocksProxyAgent } = require('socks-proxy-agent');
const { start } = require('./bot');
const mongoConnect = require('./db_connect');
const { resubscribeInvoices } = require('./ln');
const logger = require('./logger');
(async () => {
process.on('unhandledRejection', e => {
logger.error(`Unhandled Rejection: ${e.message}`);
});
process.on('uncaughtException', e => {
logger.error(`Uncaught Exception: ${e.message}`);
});
const mongoose = mongoConnect();
mongoose.connection
.once('open', async () => {
logger.info('Connected to Mongo instance.');
let options = { handlerTimeout: 60000 };
if (process.env.SOCKS_PROXY_HOST) {
const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_HOST);
options = {
telegram: {
agent,
},
};
}
const bot = start(process.env.BOT_TOKEN, options);
await resubscribeInvoices(bot);
})
.on('error', error => logger.error(`Error connecting to Mongo: ${error}`));
})();