-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpair.js
More file actions
157 lines (126 loc) Β· 5.54 KB
/
Copy pathpair.js
File metadata and controls
157 lines (126 loc) Β· 5.54 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
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
146
147
148
149
150
151
152
153
154
155
156
157
const { malvinid } = require('./id');
const express = require('express');
const fs = require('fs');
let router = express.Router();
const pino = require("pino");
const { Storage } = require("megajs");
const {
default: Malvin_Tech,
useMultiFileAuthState,
delay,
makeCacheableSignalKeyStore,
Browsers
} = require("@whiskeysockets/baileys");
// Function to generate a random Mega 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}`;
}
// Function to upload credentials to Mega
async function uploadCredsToMega(credsPath) {
try {
const storage = await new Storage({
email: 'nexusxd.bot@gmail.com', // Your Mega A/c Email Here
password: 'malvin266' // Your Mega A/c Password Here
}).ready;
console.log('Mega storage initialized.');
if (!fs.existsSync(credsPath)) {
throw new Error(`File not found: ${credsPath}`);
}
const fileSize = fs.statSync(credsPath).size;
const uploadResult = await storage.upload({
name: `${randomMegaId()}.json`,
size: fileSize
}, fs.createReadStream(credsPath)).complete;
console.log('Session successfully uploaded to Mega.');
const fileNode = storage.files[uploadResult.nodeId];
const megaUrl = await fileNode.link();
console.log(`Session Url: ${megaUrl}`);
return megaUrl;
} catch (error) {
console.error('Error uploading to Mega:', error);
throw error;
}
}
// Function to remove a file
function removeFile(FilePath) {
if (!fs.existsSync(FilePath)) return false;
fs.rmSync(FilePath, { recursive: true, force: true });
}
// Router to handle pairing code generation
router.get('/', async (req, res) => {
const id = malvinid();
let num = req.query.number;
async function MALVIN_PAIR_CODE() {
const { state, saveCreds } = await useMultiFileAuthState('./temp/' + id);
try {
let Malvin = Malvin_Tech({
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 (!Malvin.authState.creds.registered) {
await delay(1500);
num = num.replace(/[^0-9]/g, '');
const code = await Malvin.requestPairingCode(num);
console.log(`Your Code: ${code}`);
if (!res.headersSent) {
res.send({ code });
}
}
Malvin.ev.on('creds.update', saveCreds);
Malvin.ev.on("connection.update", async (s) => {
const { connection, lastDisconnect } = s;
if (connection === "open") {
await delay(5000);
const filePath = __dirname + `/temp/${id}/creds.json`;
if (!fs.existsSync(filePath)) {
console.error("File not found:", filePath);
return;
}
const megaUrl = await uploadCredsToMega(filePath);
const sid = megaUrl.includes("https://mega.nz/file/")
? 'botname-MD~' + megaUrl.split("https://mega.nz/file/")[1]
: 'Error: Invalid URL';
console.log(`Session ID: ${sid}`);
const session = await Malvin.sendMessage(Malvin.user.id, { text: sid });
const MALVIN_TEXT = `
π *Welcome to CORNEH MD!* π
π *Your Session ID* is ready! β οΈ _Keep it private and secure β dont share it with anyone._
π *Copy & Paste the SESSION_ID Above*π οΈ Add it to your environment variable: *SESSION_ID*.
π‘ *Whats Next?*
1οΈβ£ Explore all the cool features of corneh md.
2οΈβ£ Stay updated with our latest releases and support.
3οΈβ£ Enjoy seamless WhatsApp automation! π€
π *Join Our Support Channel:* π [Click Here to Join](https://whatsapp.com/channel/0029Vb32FIvD8SDyl6qmsA1b)
β *Show Some Love!* Give us a β on GitHub and support the developer of: π [Malvin King GitHub Repo](https://github.com/munaa2/)
π _Thanks for choosing CORNEH MD β Let the automation begin!_ β¨`;
await Malvin.sendMessage(Malvin.user.id, { text: MALVIN_TEXT }, { quoted: session });
await delay(100);
await Malvin.ws.close();
return removeFile('./temp/' + id);
} else if (connection === "close" && lastDisconnect && lastDisconnect.error && lastDisconnect.error.output.statusCode !== 401) {
await delay(10000);
MALVIN_PAIR_CODE();
}
});
} catch (err) {
console.error("Service Has Been Restarted:", err);
removeFile('./temp/' + id);
if (!res.headersSent) {
res.send({ code: "Service is Currently Unavailable" });
}
}
}
await MALVIN_PAIR_CODE();
});
module.exports = router;