Repository navigation
Expand file tree
/
Copy pathbot.js
More file actions
50 lines (43 loc) · 1.62 KB
/
Copy pathbot.js
File metadata and controls
50 lines (43 loc) · 1.62 KB
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
const search = require('./search-movie')
const Extra = require('telegraf/extra')
const Markup = require('telegraf/markup')
module.exports = (bot) => {
bot.command(['start', 'help', 'commands'], ctx => {
ctx.reply('Use /search (Movie Title/IMDb Code, Actor Name/IMDb Code, Director Name/IMDb Code!')
})
bot.command('search', async ctx => {
const term = ctx.message.text.split('/search')[1]
console.log(ctx.message.from)
if (term) {
const movies = await search(term)
if (movies && movies.length > 0) {
const torrentsInfo = movies.map(movie => {
return {
title: movie.title,
year: movie.year,
summary: movie.summary,
medium_cover_image: movie.medium_cover_image,
torrentInfo: movie.torrents.map(torrent => {
return {
text: `${torrent.quality} ${torrent.size}`,
url: torrent.url
}
})
}
})
torrentsInfo.forEach(info => {
const keyboard = Markup.inlineKeyboard(buildKeyboard(info.torrentInfo))
const text = `${info.title} - ${info.year}\n${info.summary} \n${info.medium_cover_image}`
sendMessage(ctx, text, keyboard)
})
} else ctx.reply('No movie found')
} else
return ctx.reply('Please provide a Movie Title/IMDb Code, Actor Name/IMDb Code or Director Name/IMDb Code')
})
}
function sendMessage(ctx, messageInfo, keyboard) {
return ctx.reply(messageInfo, Extra.markup(keyboard))
}
function buildKeyboard(links) {
return links.map(link => [{ text: link.text, url: link.url, hide: false }])
}