-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (52 loc) · 2.61 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
68
69
70
const { Telegraf } = require('telegraf')
const { message } = require('telegraf/filters')
const LocalSession = require('telegraf-session-local')
const { GenericMenu } = require('telegraf-menu')
const { callbackQuery } = require('./callbackQuery')
const { initSession } = require('./middlewares/initSession')
const { start } = require('./commands/start')
const { aboutMe } = require('./commands/aboutMe')
const { searchBand } = require('./commands/searchBand')
const {
initRandomMenu, initWorldSidesMenu, initCountryMenu,
clearRandomFilter, initSubGenreMenu, initGenreMenu,
initStatusMenu,
} = require('./commands/random')
const token = process.env.TELEGRAM_BOT_TOKEN // https://t.me/metal_Library_bot
const session = new LocalSession({ database: 'local.db.json' })
const startBot = async () => {
const bot = new Telegraf(token)
// bot.use(Telegraf.log((log) => console.log('>>> Telegraf "' + new Date().toString() + '" :' + log)));
bot.catch((error, ctx) => {
ctx.tg.sendMessage(423754317, error.toString()) // @scronheim chat id
console.log(error)
})
//======= MIDDLEWARES =======
bot.use(session.middleware())
bot.use(GenericMenu.middleware())
bot.use(initSession)
//======= /MIDDLEWARES =======
//======= COMMANDS =======
bot.command('start', start)
bot.command('random', initRandomMenu)
bot.action(new RegExp('random'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initRandomMenu))
bot.command('worldSide', initWorldSidesMenu)
bot.action(new RegExp('worldSide'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initWorldSidesMenu))
bot.command('genre', initGenreMenu)
bot.action(new RegExp('genre'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initGenreMenu))
bot.command('subGenre', initSubGenreMenu)
bot.action(new RegExp('subGenre'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initSubGenreMenu))
bot.command('status', initStatusMenu)
bot.action(new RegExp('status'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initStatusMenu))
bot.command('clearRandomFilter', clearRandomFilter)
bot.action(new RegExp('clearRandomFilter'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, clearRandomFilter))
bot.command('country', initCountryMenu)
bot.action(new RegExp('country'), GenericMenu.onAction(ctx => ctx.session.keyboardMenu, initCountryMenu))
bot.command('about', aboutMe)
bot.on(message('text'), searchBand)
bot.on('callback_query', callbackQuery)
//======= /COMMANDS =======
console.log('Telegram bot started')
await bot.launch()
}
startBot()