-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (67 loc) · 2.67 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
71
72
73
74
const { Telegraf } = require('telegraf')
const { Router, Markup } = Telegraf
var request = require('request');
var he = require('he');
const { parse } = require('node-html-parser');
const commandParts = require('telegraf-command-parts');
const headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
}
const apiKey = "XXXXX"
const bot = new Telegraf(apiKey)
bot.use(commandParts())
bot.startPolling()
bot.start((ctx) => {
ctx.replyWithMarkdown(`*.:STALKINT BOT:.*
🔥 Fotoğraf araştırması için bir fotoğraf gönderin.
`)
console.log("Yeni kullanici")
})
bot.command('twitter', ctx => {
if (ctx.state.command.args) {
ctx.reply(ctx.state.command.args)
} else {
ctx.reply("Kullanıcı adını girin!")
}
} )
bot.on('photo', async (ctx) => {
reverseSearch(ctx)
})
bot.hears('hi', async (ctx) => {
reverseSearch(ctx)
})
bot.launch()
const reverseSearch = async ctx => {
try {
console.log("Yeni fotograf arastirmasi yapiliyor")
ctx.reply("Ters görsel araması başlatılıyor..")
let link = await ctx.telegram.getFileLink(ctx.message.photo[0].file_id)
request({ url: 'https://www.google.com.tr/searchbyimage?image_url=' + link, method: 'GET', headers: headers }, (error, response, body) => {
if (response.body.includes('Tüm boyutlar')) {
urlRegExp = new RegExp(/(<a href="\/search\?tbs=simg:(.*?)">(.*?)<a href="\/search\?tbs=simg:(.*?)">Tüm boyutlar<\/a>)/)
let url = he.decode('https://www.google.com.tr/search?tbs=simg:' + response.body.match(urlRegExp)[4])
request({ url: url, method: 'GET', headers: headers }, (error, response, body) => {
let doc = parse(response.body)
var divs = doc.querySelectorAll("[rel='noopener']");
var buttonList = []
divs.forEach(el => {
buttonList.push(Markup.urlButton(el.childNodes[0].childNodes[0].rawText, el._attrs.href))
});
const buttonsKeyboard = Markup.inlineKeyboard(
buttonList
, { columns: 1 }).extra()
ctx.telegram.sendMessage(
ctx.from.id,
'Sonuçlar',
buttonsKeyboard)
//console.log(doc.querySelector("[rel='noopener']"))
//console.log(doc.querySelector("[rel='noopener']").)
})
} else {
ctx.reply("Görsel bulunamadı")
}
})
} catch (err) {
console.log(err)
}
}