-
Notifications
You must be signed in to change notification settings - Fork 1
/
war.js
569 lines (535 loc) · 23.9 KB
/
war.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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
"use strict"
const {
default: makeWASocket,
WA_DEFAULT_EPHEMERAL,
makeCacheableSignalKeyStore,
AnyMessageContent,
MessageOptions,
delay,
downloadMediaMessage,
DisconnectReason,
fetchLatestBaileysVersion,
makeInMemoryStore,
MessageRetryMap,
useMultiFileAuthState,
MessageType,
Mimetype,
proto
} = require('@whiskeysockets/baileys');
const app = require('express')();
const jsonwebtoken = require("jsonwebtoken");
const JWT_SECRET =
"";
const http = require('http').Server(app);
const port = process.env.PORT || 3017;
const {
writeFile
} = require('fs/promises')
const {
Boom
} = require('@hapi/boom')
const MAIN_LOGGER = require('@whiskeysockets/baileys/lib/Utils/logger');
const {
createSticker,
StickerTypes
} = require('wa-sticker-formatter')
const {
exec
} = require("child_process")
const pino = require('pino')
const re = /.git.*/ig;
const proxy_list = [
]
let random_index = Math.floor(Math.random() * proxy_list.length);
const fs = require('fs');
function addLeadingZeros(n) {
if (n <= 9) {
return "0" + n;
}
return n
}
let {
req,
params,
tagNum,
tagText
} = "";
const qrcode = require('qrcode-terminal');
const str_replace = require('str_replace');
const gTTS = require('gtts');
const translate = require('translate-google');
const {
id
} = require('translate-google/languages');
let msgRetryCounterMap;
msgRetryCounterMap = MessageRetryMap;
const logger = pino();
const useStore = !process.argv.includes('--no-store')
const store = useStore ? makeInMemoryStore({
logger
}) : undefined
store?.readFromFile('./baileys_store_multi.json')
// save every 10s
setInterval(() => {
store?.writeToFile('./baileys_store_multi.json')
}, 10_000)
const startSock = async () => {
const {
state,
saveCreds
} = await useMultiFileAuthState('baileys_auth_info')
const {
version,
isLatest
} = await fetchLatestBaileysVersion()
const sock = makeWASocket({
version,
printQRInTerminal: true,
auth: state,
keys: makeCacheableSignalKeyStore(state.keys, pino({
level: "error"
})),
msgRetryCounterMap,
logger,
//browser: Browsers.baileys('Desktop'),
//browser: browsers.macOS('Desktop'),
browser: ['chrome', 'Desktop', '10'],
syncFullHistory: true,
getMessage: async key => {
if (store) {
const msg = await store.loadMessage(key.remoteJid, key.id, undefined)
return msg?.message || undefined
}
// only if store is present
return {
conversation: 'hello'
}
}
})
app.get('/send/:tagNum/:tagText', (req, res) => {
const sendid = async () => {
const now = new Date();
let formattedDate = now.getFullYear() + "-" + addLeadingZeros(now.getMonth() + 1) + "-" + addLeadingZeros(now.getDate()) + " " + addLeadingZeros(now.getHours()) + ":" + addLeadingZeros(now.getMinutes()) + ":" + addLeadingZeros(now.getSeconds())
await sock.sendMessage(`${req?.params?.tagNum}@s.whatsapp.net`, {
text: `${formattedDate}${req?.params?.tagText}`
})
}
sendid();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({
text: "" + req.params.tagText + ""
}));
});
app.get('/sendz/:tagNum/:tagText', (req, res) => {
const sendid = async () => {
const now = new Date();
let formattedDate = now.getFullYear() + "-" + addLeadingZeros(now.getMonth() + 1) + "-" + addLeadingZeros(now.getDate()) + " " + addLeadingZeros(now.getHours()) + ":" + addLeadingZeros(now.getMinutes()) + ":" + addLeadingZeros(now.getSeconds())
await sock.sendMessage(`${req?.params?.tagNum}@s.whatsapp.net`, {
text: `${req?.params?.tagText}`
})
}
sendid();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({
text: "" + req.params.tagText + ""
}));
});
app.post("/sendj/:tagNum/:tagText", (req, res) => {
const {
username,
password
} = req.body;
console.log(`${username} is trying to login ..`);
if (username === "clonerxyz" && password === "Gratisselamaasik") {
return res.json({
token: jsonwebtoken.sign({
user: "clonerxyz"
}, JWT_SECRET),
});
}
return res
.status(401)
.json({
message: "The username and password your provided are invalid"
});
});
app.get('/sendg/:tagNum/:tagText', (req, res) => {
const sendid = async () => {
const now = new Date();
let formattedDate = now.getFullYear() + "-" + addLeadingZeros(now.getMonth() + 1) + "-" + addLeadingZeros(now.getDate()) + " " + addLeadingZeros(now.getHours()) + ":" + addLeadingZeros(now.getMinutes()) + ":" + addLeadingZeros(now.getSeconds())
await sock.sendMessage(`${req?.params?.tagNum}@g.us`, {
text: `${formattedDate}${req?.params?.tagText}`
})
}
sendid();
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({
text: "" + req.params.tagText + ""
}));
});
//sock.ev.on('call', (m) => { const _call = m[0]; if (_call.status == 'offer') { sock.rejectCall(_call.id); } })
sock.ev.on('call', async (node) => {
const {
from,
id,
status
} = node[0]
if (status == 'offer') {
const stanza = {
tag: 'call',
attrs: {
from: sock.user.id,
to: from,
id: sock.generateMessageTag(),
},
content: [{
tag: 'reject',
attrs: {
'call-id': id,
'call-creator': from,
count: '0',
},
content: undefined,
}, ],
}
await sock.query(stanza)
}
})
sock.ev.process(
async (events) => {
if (events['connection.update']) {
const update = events['connection.update']
const {
connection,
lastDisconnect
} = update
if (connection === 'close') {
}
if (lastDisconnect?.error?.output?.statusCode === DisconnectReason.restartRequired) {
startSock()
}
if (lastDisconnect?.error?.output?.statusCode === DisconnectReason.timedOut) {} else if (connection === 'open') {
}
}
if (events['creds.update']) {
await saveCreds()
}
if (events['chats.set']) {
const {
chats,
isLatest
} = events['chats.set']
//console.log(`recv ${chats.length} chats (is latest: ${isLatest})`)
}
if (events['call']) {
}
if (events['messages.set']) {
const {
messages,
isLatest
} = events['messages.set']
//console.log(`recv ${messages.length} messages (is latest: ${isLatest})`)
}
if (events['contacts.set']) {
const {
contacts,
isLatest
} = events['contacts.set']
//console.log(`recv ${contacts.length} contacts (is latest: ${isLatest})`)
}
if (events['messages.upsert']) {
const upsert = events['messages.upsert']
//console.log('recv messages ', JSON.stringify(upsert, undefined, 2))
if (upsert.type === 'notify') {
try {
for (const msg of upsert.messages) {
const body = (msg.message?.extendedTextMessage?.text);
const group = (msg.message?.conversation);
const namez = (msg.pushName);
const didi = (msg.key.remoteJid)
const didiz = (msg.key.participant)
const didix = str_replace('@s.whatsapp.net', '', didi)
const didiy = str_replace('@s.whatsapp.net', '', didiz)
const allc = (msg.key.remoteJid || msg.key.participant);
const didiw = str_replace('@s.whatsapp.net', '', allc)
const alls = (msg.message?.extendedTextMessage?.text || msg.message?.conversation || msg.message?.listResponseMessage?.title || msg.message?.imageMessage?.caption || msg.message?.videoMessage?.caption)
const list = (msg.message?.listResponseMessage?.title);
const stsx = (msg.message?.imageMessage?.caption || msg.message?.videoMessage?.caption);
const btrx = (msg.message?.buttonsResponseMessage?.selectedDisplayText);
const sendMessageWTyping = async (msg, didi, options = {}) => {
await sock.presenceSubscribe(didi)
await delay(500)
await sock.sendPresenceUpdate('composing', didi)
await delay(2000)
await sock.sendPresenceUpdate('paused', didi)
await sock.sendMessage(didi, msg, options)
}
console.log(`nomor : ${didix} nama : ${namez} [pesan : ${alls}]`)
//fs.appendFileSync('db.json', ''+msg+'\n' ,(err)=> {
//if(err){
// console.log('error',err);
//}
//console.log('DONE');
//})
if (alls === 'menu' || alls === 'menus' || alls === 'Menus' || alls === '.menus' || alls === 'Help' || alls === 'help' || alls === 'Menu' || alls === '.menu' || alls === 'p' || alls === 'P') {
await sock.readMessages([msg.key])
//async function menn() {
exec('cat menu.txt', async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
await sendMessageWTyping({
text: `${stdout}`
}, msg.key.remoteJid)
})
} else if (body === '1' || group === '1') {
await sock.readMessages([msg.key])
await sendMessageWTyping({
text: "hallo"
}, msg.key.remoteJid, {
quoted: msg
}, {
ephemeralExpiration: WA_DEFAULT_EPHEMERAL
})
} else if (alls?.startsWith('tle') || alls?.startsWith('Tle')) {
await sock.readMessages([msg.key])
const it = (list?.slice(4) || body?.slice(4) || group?.slice(4))
translate('' + it + '', {
from: 'auto',
to: 'en'
}).then(async res => {
console.log(res)
await sendMessageWTyping({
text: `${res}`
}, msg.key.remoteJid)
}).catch(async err => {
console.error(err)
await sendMessageWTyping({
text: `${err}`
}, msg.key.remoteJid)
})
} else if (alls?.startsWith('tlj') || alls?.startsWith('Tlj')) {
await sock.readMessages([msg.key])
const it = (list?.slice(4) || body?.slice(4) || group?.slice(4))
translate('' + it + '', {
from: 'auto',
to: 'ja'
}).then(async res => {
console.log(res)
await sendMessageWTyping({
text: `${res}`
}, msg.key.remoteJid)
}).catch(async err => {
console.error(err)
await sendMessageWTyping({
text: `${err}`
}, msg.key.remoteJid)
})
} else if (alls?.startsWith('tli') || alls?.startsWith('Tli')) {
await sock.readMessages([msg.key])
const it = (list?.slice(4) || body?.slice(4) || group?.slice(4))
translate('' + it + '', {
from: 'auto',
to: 'id'
}).then(async res => {
console.log(res)
await sendMessageWTyping({
text: `${res}`
}, msg.key.remoteJid)
}).catch(async err => {
console.error(err)
await sendMessageWTyping({
text: `${err}`
}, msg.key.remoteJid)
})
} else if (alls?.startsWith('how') || alls?.startsWith('How')) {
await sock.readMessages([msg.key])
exec('cat menu.txt', async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
//return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
//return;
}
await sendMessageWTyping({
text: `${stdout}`
}, msg.key.remoteJid)
})
} else if (alls?.startsWith('sts') || alls?.startsWith('Sts')) {
await sock.readMessages([msg.key])
const name = Math.random().toString(36).slice(8);
const pathget = (msg.message?.imageMessage?.mimetype || msg.message?.videoMessage?.mimetype)
const size = (msg.message?.videoMessage?.fileLength)
console.log(pathget)
if (size > 5000000) {
await sendMessageWTyping({
text: `kegedean mas file nya`
}, msg.key.remoteJid)
} else {
const path = str_replace('image/', '', pathget);
const pathclean = str_replace('video/', '', path);
const buffer = await downloadMediaMessage(
msg,
'buffer', {}, {
//logger,
// pass this so that baileys can request a reupload of media
// that has been deleted
reuploadRequest: sock.updateMediaMessage
}
)
// save to file
await writeFile(`img/${name}.${pathclean}`, buffer)
//await writeFile(`/root/mnt/home/clonerxyz/botwatest/img/${name}.${pathclean}`, getMedia)
const folder = ('img/')
//exec('ffmpeg -i '+folder+name+'.'+pathclean+' '+folder+name+'.webp', async(error, stdout, stderr) => {
exec('ffmpeg -i ' + folder + name + '.' + pathclean + ' -v quiet -vcodec libwebp -filter:v fps=fps=20 -lossless 1 -compression_level 6 -loop 0 -preset default -an -vsync 0 ' + folder + name + '.webp', async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
//return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
//return;
}
if (fs.existsSync(`img/${name}.webp`)) {
await sock.sendMessage(msg.key.remoteJid, {
sticker: fs.readFileSync(`img/${name}.webp`)
});
} else {
await sendMessageWTyping({
text: `kegedean mas file nya`
}, msg.key.remoteJid)
}
})
//await delay(6000)
}
} else if (alls?.startsWith('git') || alls?.match(re)) {
await sock.readMessages([msg.key])
//const text = (body || group)
const axios = require('axios');
const lang = ('id')
async function doPostRequest() {
let res = await axios.post('https://simsimi.vn/web/simtalk', {
lc: `${lang}`,
text: `${alls}`
}, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
let data = res.data;
const str = data?.success;
const str2 = str.replace(/sim.*|ing|bi|ol|cok|sat|kau|eng/ig, "");
//await sock.readMessages([msg.key])
await sock.sendMessage(msg.key.remoteJid, {
text: `${str2} `
}, {
quoted: msg
})
}
doPostRequest();
} else if (alls?.startsWith('back') || alls?.startsWith('Back')) {
await sock.readMessages([msg.key])
const parts = (list?.trim().split(' ') || body?.trim().split(' ') || group?.trim().split(' '));
const ip = parts.slice(1, 2).join(' ');
const user = parts.slice(2, 3).join(' ');
const pass = parts.slice(3, 4).join(' ');
const port = parts.slice(4).join(' ');
await sendMessageWTyping({
text: ` backup file dengan parameter\n IP = ${ip}\n USER = ${user}\n PASSWORD = ${pass}\n PORT = ${port}`
}, msg.key.remoteJid, {
quoted: msg
}, {
ephemeralExpiration: WA_DEFAULT_EPHEMERAL
}) //windows platfrom
exec(`echo yes | plink -ssh -l ${user} -pw ${pass} -P ${port} ${ip} "/export" > ${ip}.rsc`, async (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
await sendMessageWTyping({
text: `error: ${error.message}`
}, msg.key.remoteJid)
}
if (stderr) {
console.log(`stderr: ${stderr}`);
await sendMessageWTyping({
text: `stderr: ${stderr}`
}, msg.key.remoteJid)
}
});
await delay(30000)
if (fs.existsSync(`${ip}.rsc`)) {
await sock.sendMessage(msg.key.remoteJid, {
document: fs.readFileSync(`${ip}.rsc`),
fileName: `${ip}.rsc`,
mimetype: 'text/plain'
});
} else {
await sendMessageWTyping({
text: `backup tidak berhasil pastikan koneksi dari router aman`
}, msg.key.remoteJid)
}
// await delay(60000)
} else if (alls?.startsWith('https://vm.') || alls?.startsWith('https://vt.') || alls?.startsWith('https://www.tiktok.com')) {
const axios = require('axios');
//const Cookies = require('cookiejar
const {
JSDOM
} = require("jsdom");
const cheerio = require("cheerio");
await sendMessageWTyping({
text: `jika lag tunggu beberapa saat atau coba lagi `
}, msg.key.remoteJid)
async function doPostRequest() {
try {
//let res2 = await axios.post('https://api.ttsave.app/',{id:`${alls}`,hash:`018e1cd2037e5addd7ab1c6a32f917a3`,mode:`video`,locale:`en`,loading_indicator_url:`https://ttsave.app/images/slow-down.gif`,unlock_url:`https://ttsave.app/en/unlock`})
let res2 = await axios.post('https://tikdownloader.io/api/ajaxSearch', {
q: `${alls}`,
lang: `en`
}, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
let dataz = res2.data.data;
//let datax = res2.data.id;
const str2 = dataz;
const str3 = new JSDOM(str2);
const str4 = str3.window.document;
const str5 = str4.querySelector(".dl-action a");
//const str6 = str5 ? str5.dataset.href : null;
//await sock.sendMessage(msg.key.remoteJid, { text: `${str5} ` }, { quoted: msg })
await sendMessageWTyping({
video: {
url: `${str5}`
},
mimetype: 'video/mp4'
}, msg.key.remoteJid, {
quoted: msg
})
} catch (error) {
console.error(error);
}
}
doPostRequest();
}
}
} catch (e) {
console.log(e);
}
}
}
}
)
return sock
}
startSock()
http.listen(port, () => {
console.log(`server is runn`);
});