This repository has been archived by the owner on Oct 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
config.js
54 lines (43 loc) · 1.74 KB
/
config.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
/* REQUIRED PARAMETERS */
/* - TELEGRAM_TOKEN */
/* - POSTGRES DB URL */
/* OPTIONAL PARAMETERS */
/* - ADMIN_ID */
/* - ANTIFLOOD_TOLERANCE */
/* - WEBHOOK_URL <-- currently disabled! */
/* - WEBHOOK_PORT */
/* - MSG_TIMEOUT */
/* (0 to disable) */
/* --- --- --- --- --- -- */
const token = process.env.BOT_TOKEN
if (!token) throw Error('Provide a valid Telegram token as environment variable.\nEx: \x1b[4m\x1b[32mBOT_TOKEN=xxx npm start\x1b[0m\n')
const url = process.env.DATABASE_URL
if (!url) throw Error('Provide a valid Postgres database url as environment variable.\nEx: \x1b[4m\x1b[32mBOT_TOKEN=xxx DATABASE_URL=progres://user:pw@127.0.0.1:5432/tagalert npm start\x1b[0m\n')
const db_url = require('url').parse(url)
const auth = db_url.auth.split(':')
const admin_id = process.env.ADMIN_ID || null
const antiflood = parseInt(process.env.ANTIFLOOD_TOLERANCE) || 2
if (antiflood < 2) throw new Error('Antiflood tolerance minimum is 2.\n')
const msg_timeout = parseInt(process.env.MSG_TIMEOUT) || 25
module.exports = {
// database settings - a postgre database is REQUIRED!
'database': {
user: auth[0],
password: auth[1],
host: db_url.hostname,
port: db_url.port,
database: db_url.pathname.split('/')[1],
ssl: false,
max: 30,
min: 6,
idleTimeoutMillis: 1000
},
// telegram token (contact @BotFather for getting one)
'token': token,
// your admin id (contact @userinfobot to get yours)
'adminId': admin_id,
// flooding tolerance (higher = more flood), tune it as you prefer but never below 2
'antiflood': antiflood,
// timeout for deleting group messages in seconds
'msg_timeout': msg_timeout
}