-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathapp.js
59 lines (51 loc) · 2.4 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
const { WAConnection, ReconnectMode } = require("@adiwajshing/baileys")
const chalk = require("chalk");
const fs = require("fs");
class App {
App;
constructor() {
this.client = new WAConnection()
this.client.autoReconnect = ReconnectMode.onAllErrors
this.client.connectOptions.maxRetries = Infinity
this.client.connectOptions.timeoutMs = 30 * 5000
}
async listen() {
const authFile = '.auth_info_session.json'
if (fs.existsSync(authFile)) {
try {
this.client.loadAuthInfo(authFile)
await this.client.connect()
} catch (err) {
console.error(err)
}
} else {
await this.client.connect()
const authInfo = this.client.base64EncodedAuthInfo() // get all the auth info we need to restore this session
fs.writeFileSync(authFile, JSON.stringify(authInfo, null, '\t')) // save this info to a file
}
var YourNumber = this.client.user.jid.substring(0, this.client.user.jid.lastIndexOf("@"));
var filesTxt = "nomor.txt";
console.log(`${chalk.green("✓")} Whatsapp Connection is Open`)
console.log(`${chalk.green("✓")} Ready - using Account Name: ${this.client.user.name}`)
console.log(`${chalk.green("✓")} Ready - using Number of: `, YourNumber)
//console.log(countryCodes["ID"].name);
const numberRaw = fs.readFileSync(filesTxt, 'utf8')
const numberlist = numberRaw.replace(/\r/g, " ").replace(/\//g, "").replace(/\n/g, "").replace(/^\s*/, '').split(" ")
console.log(`[${chalk.yellow('Work')}] Nomor Wa yang di cek ada ${numberlist.length} nomor...`)
//let validNumber = []
await Promise.all(
numberlist.map((number, i) => new Promise((resolve, reject) => {
setTimeout(async () => {
const contactId = number.includes('@s.whatsapp.net') ? number.replace(/^\s*/, '') : number.replace(/^\s*/, '') + '@s.whatsapp.net'
const result = await this.client.isOnWhatsApp(contactId)
result ? console.log(chalk.blue.bold(number.trim(),'|AKTIF')) : console.log(chalk.bgRed(number.trim(),'|NON-WA'))
resolve()
}, i * 1000)
}
)))
console.log("Bye...");
process.exit();
}
}
const server = new App();
server.listen();