-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwasi.js
145 lines (94 loc) · 4.16 KB
/
wasi.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
// get qr code of any bot using this ....................
//coded by wasi
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 || `
┌───😘
🔰 *GOLD-MD*
🔰 _MADE BY UMAR_
└────────────😘
┌───😘
🔰 *• |HELP| •*
🔰 *GOLD-MD_REPO:* __https://github.com/D4X-UMAR/GOLD-MD_
🔰 *WHATSAPP_CHANNEL:* _https://whatsapp.com/channel/0029VabdDuf7DAWylTkTZa0m_
🔰 *WHATSAPP_GROUP:* _https://chat.whatsapp.com/II4CelPFUvIFeK6f8hdJuX_
└────────────😘
`
if (fs.existsSync('./auth_info_baileys')) {
fs.emptyDirSync(__dirname + '/auth_info_baileys');
};
app.use("/", async(req, res) => {
const { default: WasiWASocket, useMultiFileAuthState, Browsers, delay,DisconnectReason, makeInMemoryStore, } = require("@whiskeysockets/baileys");
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
async function WASI() {
const { state, saveCreds } = await useMultiFileAuthState(__dirname + '/auth_info_baileys')
try {
let Smd =WasiWASocket({
printQRInTerminal: false,
logger: pino({ level: "silent" }),
browser: [Browsers.Chrome, 'Windows 10', 'Chrome/89.0.4389.82'],
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!")
// WASI().catch(err => console.log(err));
} else if (reason === DisconnectReason.connectionLost) {
console.log("Connection Lost from Server!")
// WASI().catch(err => console.log(err));
} else if (reason === DisconnectReason.restartRequired) {
console.log("Restart Required, Restarting...")
WASI().catch(err => console.log(err));
} else if (reason === DisconnectReason.timedOut) {
console.log("Connection TimedOut!")
// WASI().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');
}
}
WASI().catch(async(err) => {
console.log(err)
await fs.emptyDirSync(__dirname+'/auth_info_baileys');
//// MADE BY ITXWASI
});
})
app.listen(PORT, () => console.log(`App listened on port http://localhost:${PORT}`));