-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexbckup.js
483 lines (463 loc) · 16.9 KB
/
indexbckup.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
// import Axios from "axios";
const {
Client,
LegacySessionAuth,
LocalAuth,
MessageMedia,
// RemoteAuth,
} = require("whatsapp-web.js");
const qrcode = require("qrcode-terminal");
const fs = require("fs");
const Axios = require("axios");
var FormData = require("form-data");
// const {
// Sticker,
// createSticker,
// StickerTypes,
// } = require("wa-sticker-formatter-gsf");
// var webp = require("webp-converter-jr");
const { Blob } = require("buffer");
const { URLSearchParams } = require("url");
// const extractFrames = require("ffmpeg-extract-frames");
var express = require("express");
var app = express();
var path = require("path");
// const { MongoStore } = require("wwebjs-mongo");
const mongoose = require("mongoose");
const { setTimeout } = require("timers/promises");
app.use("/public", express.static(path.join(__dirname + "/public")));
// mongoose
// .connect(
// "mongodb+srv://aditya:[email protected]/SessionData"
// )
// .then(() => {
// const store = new MongoStore({ mongoose: mongoose });
const client = new Client({
userAgent:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
puppeteer: {
// executablePath: "/usr/bin/google-chrome-stable",
},
// authStrategy: new LocalAuth({
// clientId: "client-one",
// }),
puppeteer: {
headless: true,
// args: ["--no-sandbox", "--disable-setuid-sandbox"],
// headless: false,
},
authStrategy: new LocalAuth({ clientId: "client-one" }),
// authStrategy: new RemoteAuth({
// store: store,
// backupSyncMs: 300000,
// }),
});
//const client2 = new Client({
// userAgent:
// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36",
// puppeteer: {
// executablePath: "/usr/bin/google-chrome-stable",
// },
// authStrategy: new LocalAuth({
// clientId: "client-one",
// }),
// puppeteer: {
// headless: true,
// args: ["--no-sandbox", "--disable-setuid-sandbox"],
// headless: false,
// },
// authStrategy: new LocalAuth({ clientId: "client-two" }),
// authStrategy: new RemoteAuth({
// store: store,
// backupSyncMs: 300000,
// }),
//});
//Start Of Client.On Codes
client.on("authenticated", (session) => {
console.log("WHATSAPP WEB => Authenticated");
});
client.on("ready", async () => {
console.log("WHATSAPP WEB => Ready");
});
client.on("qr", (qr) => {
qrcode.generate(qr, { small: true });
});
//client2.on("authenticated", (session) => {
// console.log("WHATSAPP WEB => Authenticated");
//});
//client2.on("ready", async () => {
// console.log("WHATSAPP WEB => Ready");
//});
//client2.on("qr", (qr) => {
// qrcode.generate(qr, { small: true });
//});
client.on("message", async (msg) => {
if (msg.body.toUpperCase() == "HEY BOOGY") {
msg.reply("hey " + msg._data.notifyName + " How It's Going .. Bro😎");
var msgtosend = MessageMedia.fromFilePath("./public/Boogy.webp");
msg.reply(msgtosend, "", { sendMediaAsSticker: true });
}
if (msg._data.type == "sticker") {
// console.log(msg);
// msg.downloadMedia().then((e) => {
// console.log(JSON.stringify(e));
// fs.writeFile(
// "./public/BoogyLazyJSON.json",
// JSON.stringify(e),
// (d) => {
// console.log(d);
// }
// );
// });
// client.sendMessage(msg._data.id._serialized.split("_")[1], e, {
// sendMediaAsSticker: true,
// stickerName: "Boogy Bot!",
// stickerAuthor: "By Aditya Kumar!!",
// });
// });
}
// console.log(msg);
});
var reg = new RegExp("^[0-9]*$");
client.on("message_create", async (m) => {
// console.log(m);
if (m._data.id.fromMe) {
// console.log(m);
if (m._data.body?.length >= 10) {
if (m._data.body.substring(0, 8).toUpperCase() == "SPAMHERE") {
const tosenddat = m._data.body.substring(9, m._data.body.length);
// console.log(tosenddat);
const tosendCount = m._data.body.substring(8, 12).trim();
if (m.hasQuotedMsg) {
if (reg.test(tosendCount)) {
if (m._data.quotedMsg.type == "chat") {
m.delete(true);
for (let index = 0; index < tosendCount; index++) {
await client.sendMessage(m._data.to, m._data.quotedMsg.body);
}
} else if (m._data.quotedMsg.type == "sticker") {
if (reg.test(tosendCount)) {
var msgtosend = MessageMedia.fromFilePath(
"./public/BoogyLazy.webp"
);
var delidsnd = await client.sendMessage(
m._data.id._serialized.split("_")[1],
msgtosend,
{ sendMediaAsSticker: true }
);
var delid = await client.sendMessage(
m._data.id._serialized.split("_")[1],
"Wait Bro Feeling Lazy...",
{ sendMediaAsSticker: true }
);
// console.log("hmm");
// console.log(m._data.to);
m.getQuotedMessage().then(async (dat) => {
m.delete(true);
if (dat.hasMedia) {
var dd = await dat.downloadMedia();
var doneOnce = false;
var chatdat = await client.sendMessage(
dat._data.id._serialized.split("_")[1],
dd,
{
sendMediaAsSticker: true,
stickerName: "Boogy Bot!",
stickerAuthor: "By Aditya Kumar!!",
}
);
for (let index = 0; index < tosendCount; index++) {
chatdat.forward(dat._data.id._serialized.split("_")[1]);
if (index == tosendCount - 1) {
await client.sendMessage(
dat._data.id._serialized.split("_")[1],
`Done ${tosendCount} Sent!`
);
delidsnd.delete(true);
// setTimeout(() => {}, 1000);
}
}
delid.delete(true);
// if (!doneOnce) {
// setTimeout(() => {
// setTimeout(() => {}, 100);
// }, 1000);
// doneOnce = true;
// }
}
});
}
} else if (m._data.quotedMsg.isGif) {
m.getQuotedMessage().then(async (dat) => {
m.delete(true);
if (dat.hasMedia) {
// var dd = await dat.downloadMedia();
// console.log(dd);
// await fs.writeFileSync(
// "stickerName.mp4",
// new Buffer.from(dd.data, "base64")
// );
// // var datbuf = await new Buffer.from(dd.data, "base64");
// var msgofbuf = MessageMedia.fromFilePath("stickerName.mp4");
// client.sendMessage(
// dat._data.id._serialized.split("_")[1],
// dd,
// {
// sendVideoAsGif: true,
// }
// );
// await extractFrames({
// input: "stickerName.mp4",
// output: `./temp/for${
// dat._data.id._serialized.split("_")[2]
// }/frame-%d.png`,
// });
// fs.readdir(
// `./temp/for${dat._data.id._serialized.split("_")[2]}`,
// {},
// (f) => console.log(f)
// );
//To Do-------------|
// Take All Frames of Video
// SAVE All
// Make All JPG TO WEBP(Web Pictures)
// Make Animation From All Given WEBP Images
// Take Animated WEBP FILE MAKE Message Media
// Sent It ......🙌🙌🙌💕👍⭐⭐⭐⭐⭐⭐⭐⭐⭐
// var formData = new FormData();
// formData.append("class", "image");
// formData.append("from", "video");
// formData.append("to", "webp");
// formData.append("source", "upload");
// formData.append("file", datbuf, "stickerName.mp4");
// fs.writeFile(
// "stickerName.mp4",
// new Buffer.from(dd.data, "base64")
// );
// console.log(dat);
// console.log(formData);
// var dt = await Axios.request({
// method: "POST",
// url: "https://hostspeedy.onlineconverter.com/file/send",
// data: formData,
// headers: {
// ...formData.getHeaders()
// },
// });
// console.log(dt);
// var readdat = await fs.readFile();
// Axios.post()
// Axios.post(
// "https://hostspeedy.onlineconverter.com/file/send",
// formData,
// {}
// ).then((dat) => {
// console.log(dat.data);
// });
// var buff = new Buffer.from(dd.data, "base64");
// fs.writeFile(
// "stickerName.mp4",
// new Buffer.from(dd.data, "base64"),
// async () => {
// fs.readFile("stickerName.mp4", (d) => {
// var formData = new FormData();
// formData.append("class", "image");
// formData.append("from", "video");
// formData.append("to", "webp");
// formData.append("source", "upload");
// formData.append(
// "file",
// new Buffer.from(dd.data, "base64"),
// {
// filename: "stickerName.mp4",
// contentType: "video/mp4",
// }
// );
// axios
// .post(
// "https://hostspeedy.onlineconverter.com/file/send",
// formData,
// {
// headers: {
// "Content-Type": "multipart/form-data",
// },
// }
// )
// .then((dat) => {
// console.log(dat);
// });
// });
// }
// );
// const buffer = await createSticker(
// new Buffer.from(dd.data, "base64"),
// {
// pack: "Boggy Bot!",
// author: "Aditya",
// type: StickerTypes.FULL,
// categories: ["🤩", "🎉"],
// id: "12345",
// quality: 50,
// background: "#000000",
// }
// );
// console.log(buffer);
// for (let index = 0; index < tosendCount; index++) {
// client.sendMessage(
// dat._data.id._serialized.split("_")[1],
// dd,
// {
// sendVideoAsGif: true,
// }
// );
// }
}
});
} else if (m._data.quotedMsg.type == "image") {
if (reg.test(tosendCount)) {
var msgtosend = MessageMedia.fromFilePath(
"./public/BoogyLazy.webp"
);
var delidsnd = await client.sendMessage(
m._data.id._serialized.split("_")[1],
msgtosend,
{ sendMediaAsSticker: true }
);
var delid = await client.sendMessage(
m._data.id._serialized.split("_")[1],
"Wait Bro Feeling Lazy...",
{ sendMediaAsSticker: true }
);
m.getQuotedMessage().then(async (dat) => {
m.delete(true);
if (dat.hasMedia) {
var dd = await dat.downloadMedia();
var doneOnce = false;
var datmsg = await client.sendMessage(
dat._data.id._serialized.split("_")[1],
dd,
{
sendMediaAsSticker: true,
stickerName: "Boogy Bot!",
stickerAuthor: "By Aditya Kumar!!",
}
);
for (let index = 0; index < tosendCount; index++) {
datmsg.forward(dat._data.id._serialized.split("_")[1]);
// if (!doneOnce) {
// setTimeout(() => {
// setTimeout(() => {}, 100);
// }, 1000);
// doneOnce = true;
// }
if (index == tosendCount - 1) {
await client.sendMessage(
dat._data.id._serialized.split("_")[1],
`Done ${tosendCount} Sent!`
);
delidsnd.delete(true);
setTimeout(() => {}, 1000);
}
}
delid.delete(true);
}
});
}
}
}
}
if (tosenddat.includes("dp")) {
m.delete(true);
var msgtosend = MessageMedia.fromFilePath("./public/BoogyLazy.webp");
var delidsnd = await client.sendMessage(
m._data.id._serialized.split("_")[1],
msgtosend,
{ sendMediaAsSticker: true }
);
var delid = await client.sendMessage(
m._data.id._serialized.split("_")[1],
"Wait Bro Feeling Lazy...",
{ sendMediaAsSticker: true }
);
const sdt = tosenddat.substring(3, 6);
var pic = await client.getProfilePicUrl(
m._data.id._serialized.split("_")[1]
);
const makemsg = await MessageMedia.fromUrl(pic);
var doneOnce = false;
var darsmgc = await client.sendMessage(m._data.to, makemsg, {
sendMediaAsSticker: true,
stickerName: "Boggy Bot!",
stickerAuthor: "By Aditya!!",
});
for (let index = 0; index < sdt; index++) {
darsmgc.forward(m._data.id._serialized.split("_")[1]);
// if (!doneOnce) {
// setTimeout(() => {}, 1000);
// doneOnce = true;
// }
if (index == sdt - 1) {
await client.sendMessage(
m._data.id._serialized.split("_")[1],
`Done ${tosendCount} Sent!`
);
delidsnd.delete(true);
// setTimeout(() => {}, 1000);
}
}
delid.delete(true);
}
}
}
}
});
//end Of Client.On Codes
(async () => {
await client.initialize();
// await client.destroy();
// await client2.initialize();
// await client2.destroy();
})();
// });
app.use(express.static(__dirname + "/"));
app.get("/", (req, res) => {
res.sendFile(path.resolve(__dirname, "./index.html"));
});
app.post("/forwardmsg", (req, res) => {
(async () => {
await client2.sendMessage("[email protected]", `HI its boogy Bot!`);
await client2.sendMessage("[email protected]", req.body.for);
client2.on("message_create", (msg) => {
if (msg._data.id.fromMe) {
// console.log(msg._data.id._serialized.split("_")[1]);
}
});
})();
});
app.listen(process.env.PORT || 8080, () => {
console.log(
`listen started on http://localhost:${
process.env.PORT ? process.env.PORT : "8080"
}`
);
});
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time);
});
}
// const client = new Client();
// const client = new Client({
// puppeteer: {
// executablePath: "/usr/bin/brave-browser-stable",
// },
// authStrategy: new LocalAuth({
// clientId: "client-one",
// }),
// puppeteer: {
// headless: true,
// args: ["--no-sandbox", "--disable-setuid-sandbox"],
// // headless: false,
// },
// });
// client.initialize();