-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpair.js
More file actions
114 lines (99 loc) · 4.41 KB
/
pair.js
File metadata and controls
114 lines (99 loc) · 4.41 KB
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
const express = require('express');
const fs = require('fs');
const { exec } = require("child_process");
let router = express.Router()
const pino = require("pino");
const {
default: makeWASocket,
useMultiFileAuthState,
delay,
makeCacheableSignalKeyStore,
Browsers,
jidNormalizedUser
} = require("@whiskeysockets/baileys");
const { upload } = require('./mega');
function removeFile(FilePath) {
if (!fs.existsSync(FilePath)) return false;
fs.rmSync(FilePath, { recursive: true, force: true });
}
router.get('/', async (req, res) => {
let num = req.query.number;
async function PrabathPair() {
const { state, saveCreds } = await useMultiFileAuthState(`./session`);
try {
let PrabathPairWeb = makeWASocket({
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, pino({ level: "fatal" }).child({ level: "fatal" })),
},
printQRInTerminal: false,
logger: pino({ level: "fatal" }).child({ level: "fatal" }),
browser: Browsers.macOS("Safari"),
});
if (!PrabathPairWeb.authState.creds.registered) {
await delay(1500);
num = num.replace(/[^0-9]/g, '');
const code = await PrabathPairWeb.requestPairingCode(num);
if (!res.headersSent) {
await res.send({ code });
}
}
PrabathPairWeb.ev.on('creds.update', saveCreds);
PrabathPairWeb.ev.on("connection.update", async (s) => {
const { connection, lastDisconnect } = s;
if (connection === "open") {
try {
await delay(10000);
const sessionPrabath = fs.readFileSync('./session/creds.json');
const auth_path = './session/';
const user_jid = jidNormalizedUser(PrabathPairWeb.user.id);
function randomMegaId(length = 6, numberLength = 4) {
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
const number = Math.floor(Math.random() * Math.pow(10, numberLength));
return `${result}${number}`;
}
let sessionXeon = fs.readFileSync(auth_path + 'creds.json', 'utf-8');
await PrabathPairWeb.sendMessage(PrabathPairWeb.user.id, { text: `*SESSION ID GENERATED SUCCESSFULY* ✅\n` });
await delay(1000 * 2);
const xeonses = await PrabathPairWeb.sendMessage(PrabathPairWeb.user.id, { text: sessionXeon });
await PrabathPairWeb.sendMessage(PrabathPairWeb.user.id, { text: `*SESSION ID GENERATED SUCCESSFULY* ✅
*Gɪᴠᴇ ᴀ ꜱᴛᴀʀ ᴛᴏ ʀᴇᴘᴏ ꜰᴏʀ ᴄᴏᴜʀᴀɢᴇ* 🌟
https://github.com/TraderAn-King/Ben-bot
*Sᴜᴘᴘᴏʀᴛ Gʀᴏᴜᴘ ꜰᴏʀ ϙᴜᴇʀʏ* 💭
https://t.me/Ronix_tech
https://whatsapp.com/channel/0029Vasu3qP9RZAUkVkvSv32
*Yᴏᴜ-ᴛᴜʙᴇ ᴛᴜᴛᴏʀɪᴀʟꜱ* 🪄
https://youtube.com/@nothingben01?si=kMgsSUMmgAtfRfVE
*BEN-WHATTSAPP-BOT* 🥀 ` }, {quoted: xeonses});
} catch (e) {
exec('pm2 restart prabath');
}
await delay(100);
return await removeFile('./session');
process.exit(0);
} else if (connection === "close" && lastDisconnect && lastDisconnect.error && lastDisconnect.error.output.statusCode !== 401) {
await delay(10000);
PrabathPair();
}
});
} catch (err) {
exec('pm2 restart prabath-md');
console.log("service restarted");
PrabathPair();
await removeFile('./session');
if (!res.headersSent) {
await res.send({ code: "Service Unavailable" });
}
}
}
return await PrabathPair();
});
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
exec('pm2 restart prabath');
});
module.exports = router;