-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathindex.js
143 lines (93 loc) · 4.35 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
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
const express = require("express");
const app = express();
const pino = require("pino");
let { toBuffer } = require("qrcode");
const path = require('path');
const fs = require("fs-extra");
const { Boom } = require("@hapi/boom");
const PORT = process.env.PORT || 5000
const MESSAGE = process.env.MESSAGE || `
╔════◇
║ *『 WAOW YOU CHOOSE SUHAIL-MD 』*
║ _You complete first step to making Bot._
╚════════════════════════╝
╔═════◇
║ 『••• 𝗩𝗶𝘀𝗶𝘁 𝗙𝗼𝗿 𝗛𝗲𝗹𝗽 •••』
║ *Ytube:* _youtube.com/SuhailTechInfo_
║ *Owner:* _https://wa.me/923184474176_
║ *Note :*_Don't provide your SESSION_ID to_
║ _anyone otherwise that can access chats_
╚════════════════════════╝
`
if (fs.existsSync('./auth_info_baileys')) {
fs.emptyDirSync(__dirname + '/auth_info_baileys');
};
app.use("/", async(req, res) => {
const { default: SuhailWASocket, useMultiFileAuthState, Browsers, delay,DisconnectReason, makeInMemoryStore, } = require("@whiskeysockets/baileys");
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
async function SUHAIL() {
const { state, saveCreds } = await useMultiFileAuthState(__dirname + '/auth_info_baileys')
try {
let Smd =SuhailWASocket({
printQRInTerminal: false,
logger: pino({ level: "silent" }),
browser: Browsers.baileys("Desktop"),
auth: state
});
Smd.ev.on("connection.update", async (s) => {
const { connection, lastDisconnect, qr } = s;
if (qr) { res.end(await toBuffer(qr)); }
if (connection == "open"){
await delay(3000);
let user = Smd.user.id;
//===========================================================================================
//=============================== SESSION ID ===========================================
//===========================================================================================
let CREDS = fs.readFileSync(__dirname + '/auth_info_baileys/creds.json')
var Scan_Id = Buffer.from(CREDS).toString('base64')
// res.json({status:true,Scan_Id })
console.log(`
==================== SESSION ID ==========================
SESSION-ID ==> ${Scan_Id}
------------------- SESSION CLOSED -----------------------
`)
let msgsss = await Smd.sendMessage(user, { text: Scan_Id });
await Smd.sendMessage(user, { text: MESSAGE } , { quoted : msgsss });
await delay(1000);
try{ await fs.emptyDirSync(__dirname+'/auth_info_baileys'); }catch(e){}
}
Smd.ev.on('creds.update', saveCreds)
if (connection === "close") {
let reason = new Boom(lastDisconnect?.error)?.output.statusCode
// console.log("Reason : ",DisconnectReason[reason])
if (reason === DisconnectReason.connectionClosed) {
console.log("Connection closed!")
// SUHAIL().catch(err => console.log(err));
} else if (reason === DisconnectReason.connectionLost) {
console.log("Connection Lost from Server!")
// SUHAIL().catch(err => console.log(err));
} else if (reason === DisconnectReason.restartRequired) {
console.log("Restart Required, Restarting...")
SUHAIL().catch(err => console.log(err));
} else if (reason === DisconnectReason.timedOut) {
console.log("Connection TimedOut!")
// SUHAIL().catch(err => console.log(err));
} else {
console.log('Connection closed with bot. Please run again.');
console.log(reason)
//process.exit(0)
}
}
});
} catch (err) {
console.log(err);
await fs.emptyDirSync(__dirname+'/auth_info_baileys');
}
}
SUHAIL().catch(async(err) => {
console.log(err)
await fs.emptyDirSync(__dirname+'/auth_info_baileys');
//// MADE WITH
});
})
app.listen(PORT, () => console.log(`App listened on port http://localhost:${PORT}`));