-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
61 lines (51 loc) · 1.35 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
import Knex from 'knex'
import dotenv from 'dotenv'
import Telegraf from 'telegraf'
import puppeteer from 'puppeteer'
import dbConfig from './knexfile.js'
import {
langsCommand,
removeAction,
startCommand,
themeCommand,
entityHandler,
} from './handlers/index.js'
dotenv.load()
const { NODE_ENV, BOT_USER, BOT_TOKEN } = process.env
const knex = Knex(dbConfig[NODE_ENV])
/**
* Gets the property value.
*
* @param {ElementHandle|JSHandle} el Element
* @param {String} propName The property name
* @return {String} The property value.
*/
const getPropertyValue = async (el, propName) => {
const prop = await el.getProperty(propName)
const value = await prop.jsonValue()
return value
}
/**
* Run main programm
*/
const run = async () => {
const browser = await puppeteer.launch({
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
})
const bot = new Telegraf(BOT_TOKEN, { username: BOT_USER })
bot.context.db = knex
bot.command('/start', startCommand)
bot.command('/start@cris_highlight_bot', startCommand)
bot.command('/langs', langsCommand)
bot.command('/langs@cris_highlight_bot', langsCommand)
bot.command('/theme', themeCommand)
bot.command('/theme@cris_highlight_bot', themeCommand)
bot.entity(...entityHandler(browser))
bot.action(...removeAction())
bot.launch()
}
run()