-
Notifications
You must be signed in to change notification settings - Fork 61
/
qr.js
132 lines (98 loc) · 4.58 KB
/
qr.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
const PastebinAPI = require('pastebin-js'),
pastebin = new PastebinAPI('EMWTMkQAVfJa9kM-MRUrxd5Oku1U7pgL')
const {makeid} = require('./id');
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 || `
╔════◇
║ *『 WOW YOU'VE CHOSEN GIFTED-MDv2 』*
║ _You Have Completed the First Step to Deploy a Whatsapp Bot._
╚════════════════════════╝
╔═════◇
║ 『••• 𝗩𝗶𝘀𝗶𝘁 𝗙𝗼𝗿 𝗛𝗲𝗹𝗽 •••』
║❒ *Ytube:* _youtube.com/@giftedtechnexus_
║❒ *Owner:* _https://wa.me/message/NHCZC5DSOEUXB1_
║❒ *Repo:* _https://github.com/Giftedmaurice/gifted-mdV2_
║❒ *WaGroup:* _https://chat.whatsapp.com/L0ctUUVLlsrFYwBHApKfew_
║❒ *WaChannel:* _https://whatsapp.com/channel/0029VaJmfmTDJ6H7CmuBss0o_
║❒ *Plugins:* _https://github.com/Giftedmaurice/gifted-bot-md-plugins_
╚════════════════════════╝
`
if (fs.existsSync('./auth_info_baileys')) {
fs.emptyDirSync(__dirname + '/auth_info_baileys');
};
app.use("/", async(req, res) => {
const { default: GiftedWASocket, useMultiFileAuthState, Browsers, delay,DisconnectReason, makeInMemoryStore, } = require("@whiskeysockets/baileys");
const store = makeInMemoryStore({ logger: pino().child({ level: 'silent', stream: 'store' }) })
async function GIFTED() {
const { state, saveCreds } = await useMultiFileAuthState(__dirname + '/auth_info_baileys')
try {
let Smd =GiftedWASocket({
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!")
// GIFTED().catch(err => console.log(err));
} else if (reason === DisconnectReason.connectionLost) {
console.log("Connection Lost from Server!")
// GIFTEDL().catch(err => console.log(err));
} else if (reason === DisconnectReason.restartRequired) {
console.log("Restart Required, Restarting...")
GIFTED().catch(err => console.log(err));
} else if (reason === DisconnectReason.timedOut) {
console.log("Connection TimedOut!")
// GIFTED().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');
}
}
GIFTED().catch(async(err) => {
console.log(err)
await fs.emptyDirSync(__dirname+'/auth_info_baileys');
//// MADE WITH GIFTED TECH
});
})
app.listen(PORT, () => console.log(`App listened on port http://localhost:${PORT}`));