forked from lnp2pBot/bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
42 lines (39 loc) · 1.29 KB
/
app.ts
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
import "dotenv/config";
import { SocksProxyAgent } from "socks-proxy-agent";
import { MainContext, start } from "./bot/start";
import { connect as mongoConnect } from './db_connect'
const { resubscribeInvoices } = require('./ln');
import { logger } from "./logger";
import { Telegraf } from "telegraf";
const { delay } = require('./util');
(async () => {
process.on('unhandledRejection', e => {
if (e) {
logger.error(`Unhandled Rejection: ${e}`);
}
});
process.on('uncaughtException', e => {
if (e) {
logger.error(`Uncaught Exception: ${e}`);
}
});
const mongoose = mongoConnect();
mongoose.connection
.once('open', async () => {
logger.info('Connected to Mongo instance.');
let options: Partial<Telegraf.Options<MainContext>> = { handlerTimeout: 60000 };
if (process.env.SOCKS_PROXY_HOST) {
const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_HOST);
options = {
telegram: {
agent,
},
};
}
const bot = start(String(process.env.BOT_TOKEN), options);
// Wait 1 seconds before try to resubscribe hold invoices
await delay(1000);
await resubscribeInvoices(bot);
})
.on('error', (error: Error) => logger.error(`Error connecting to Mongo: ${error}`));
})();