-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
593 lines (580 loc) · 22.3 KB
/
index.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
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
const { create, decryptMedia } = require('@open-wa/wa-automate')
const fs = require('fs-extra')
const moment = require('moment')
const fetch = require('node-fetch')
const axios = require('axios')
const get = require('got')
const {artinama,
quotes,
weton,
corona,
alay,
namaninjaku,
liriklagu,
quotemaker,
yt,
gd,
jodoh,
hilih,
weather,
} = require('./lib/functions')
const quotedd = require('./lib/quote')
const videoUrlLink = require('video-url-link')
const tiktok = require('./lib/dl-video')
const fbvid = require('fbvideos');
const serverOption = {
headless: true,
qrRefreshS: 60,
qrTimeout: 0,
authTimeout: 0,
autoRefresh: true,
devtools: false,
cacheEnabled:false,
chromiumArgs: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--aggressive-cache-discard',
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0'
]
}
const opsys = process.platform;
if (opsys == "win32" || opsys == "win64") {
serverOption['executablePath'] = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
} else if (opsys == "linux") {
serverOption['browserRevision'] = '737027';
} else if (opsys == "darwin") {
serverOption['executablePath'] = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
}
const startServer = async (from) => {
create('Imperial', serverOption)
.then(client => {
console.log('[SERVER] Server Started!')
// Force it to keep the current session
client.onStateChanged(state => {
console.log('[State Changed]', state)
if (state === 'CONFLICT') client.forceRefocus()
})
client.onMessage((message) => {
msgHandler(client, message)
})
client.onIncomingCall(call => {
console.log(call)
client.contactBlock(call.peerJid)
})
})
}
async function msgHandler (client, message) {
try {
// console.log(message)
const { type, body, from, t, sender, isGroupMsg, chat, groupMetadata, caption, isMedia, mimetype, quotedMsg } = message
const { id, pushname } = sender
const { name } = chat
const pushnames = sender.pushname || chat.name || sender.verifiedName || '';
const time = moment(t * 1000).format('DD/MM HH:mm:ss')
const commands = ['#sticker',
'#stiker',
'#donate',
'#donasi',
'#dujin',
'#info',
'#tiktok',
'#F',
'#join',
'#lirik',
'#quotemaker',
'#menu',
'#owner',
'#meme',
'#setPic',
'#add',
'#kick',
'#leave',
'#promote',
'#demote',
'#admin',
'#linkGrup',
'#revLinkGrup',
'#getPic',
'#neko',
'#wallpaper',
'#quote',
'#quotes',
'#Quote',
'#weather',
'#Tod',
'#Pokemon',
'#waifu',
'#Waifu',
'#fb',
'#ytmp3',
'#ig',
'#gifSticker',
'#setName',
'#setDesc',
'#gifStiker']
const cmds = commands.map(x => x + '\\b').join('|')
const cmd = type === 'chat' ? body.match(new RegExp(cmds, 'gi')) : type === 'image' && caption ? caption.match(new RegExp(cmds, 'gi')) : ''
if (cmd) {
if (!isGroupMsg) console.log(color('[EXEC]'), color(time, 'yellow'), color(cmd[0]), 'from', color(pushname))
if (isGroupMsg) console.log(color('[EXEC]'), color(time, 'yellow'), color(cmd[0]), 'from', color(pushname), 'in', color(name))
const args = body.trim().split(' ')
switch (cmd[0]) {
case '#sticker':
case '#stiker':
if (isMedia) {
const mediaData = await decryptMedia(message)
const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}`
await client.sendImageAsSticker(from, imageBase64, message)
} else if (quotedMsg && quotedMsg.type == 'image') {
const mediaData = await decryptMedia(quotedMsg)
const imageBase64 = `data:${quotedMsg.mimetype};base64,${mediaData.toString('base64')}`
await client.sendImageAsSticker(from, imageBase64, message)
} else if (args.length == 2) {
var isUrl = new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi);
const url = args[1]
if (url.match(isUrl)) {
await client.sendStickerfromUrl(from, url, { method: 'get' })
.catch(err => console.log('Caught exception: ', err))
} else {
client.sendText(from, 'Url is invalid')
}
} else {
if(isGroupMsg) {
client.sendTextWithMentions(from, `Dasar @${message.author} bodoh!, yang mau dijadiin stiker apa? lu cuma send teks *#stiker*. kalo mau bikin stiker send foto dengan caption *#stiker*.`)
} else {
client.reply(from, 'Dasar bodoh!, yang mau di jadiin stiker apa? Lu cuma send teks *#stiker*. kalo mau bikin stiker send foto dengan caption *#stiker*', message)
}
}
break
/*case '#gifSticker':
case '#gifStiker':
if (args.length == 1){
const url = args[0]
const isMediaGiphy = url.match(new RegExp(/https?:\/\/media.giphy.com\/media/, 'gi'));
const isGiphy = url.match(new RegExp(/https?:\/\/(www\.)?giphy.com/, 'gi'));
if(isGiphy){
const getGiphyCode = url.match(new RegExp(/\-(?:.(?!\-))+$/, 'gi'));
if(getGiphyCode){
let delHyphen = getGiphyCode[0].replace(/-/gi, "");
const smallGif = "https://media.giphy.com/media/"+delHyphen+"/giphy-downsized.gif";
await client.sendGiphyAsSticker(from, smallGif)
.catch((err) => {
console.log(err)
})
} else {
client.reply(from, "Gagal membuat sticker gif", id)
}
} else if(isMediaGiphy){
const normalGif = url.match(new RegExp(/(giphy|source).(gif|mp4)/, 'gi'));
if(normalGif){
let smallGif = url.replace(normalGif[0], "giphy-downsized.gif")
await client.sendGiphyAsSticker(from, smallGif)
.catch((err) => {
console.log(err)
})
}
} else {
client.reply(from, "Saat ini sticker gif hanya bisa menggunakan link giphy saja kak.", id)
}
}
break*/
case '#setPic':
if(isGroupMsg) {
if(isMedia) {
var wkk = `${from.split('-')[0]}@c.us`
if(message.author == wkk || message.author == '[email protected]') {
const mediaData = await decryptMedia(message)
const imageBase64 = `data:${mimetype};base64,${mediaData.toString('base64')}`
await client.setGroupIcon(from, imageBase64)
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
} else {
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
case '#setDesk':
if(isGroupMsg) {
var wkk = `${from.split('-')[0]}@c.us`
if(message.author == wkk || message.author == '[email protected]') {
try {
const desk = body.slice(9)
await client.setGroupDescription(from, `${desk}`)
} catch {
client.reply(from, 'Terjadi kesalahan, tidak dapat mengubah deskripsi grup', message)
}
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}else{
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
case '#donasi':
case '#donate':
client.sendLinkWithAutoPreview(from,'Ya halo, mau donate?\n\nKalo mau donate nih langsung ae ke:\nDANA/GOPAY : 081246114524\nPulsa : 081246114524')
break
case '#tod':
if (args.length == 2) {
const url = args[1]
const reUrl = url.match(new RegExp(/https?:\/\/media.giphy.com\/media/, 'gi'))
if(reUrl) {
await client.sendGiphyAsSticker(from, url)
} else {
client.reply(from, 'Untuk saat ini stiker gif hanya bisa menggunakan link giphy saja', message)
}
}
break
case '#ytmp3':
if (args.length >= 2){
const url = args[1]
var param = body.substring(body.indexOf(' '), body.length)
const resp = await get.get('https://yutmp3.herokuapp.com/?url='+ param).json()
console.log(resp)
if (!resp.file) {
client.reply(from, 'Videonya ga valid!', message)
} else {
client.reply(from, `Title : ${resp.title}`, message)
await client.sendFileFromUrl(from, `https://yutmp3.herokuapp.com${resp.file}`, `${resp.title}.mp3`)
}
}
break
case '#tiktok':
if (args.length !== 1) return client.reply(from, 'Maaf, format pesan salah silahkan periksa menu.', id)
if (!url.match(isUrl) && !url.includes('tiktok.com')) return client.reply(from, 'Maaf, link yang kamu kirim tidak valid', id)
await client.sendText(from, '*Scraping Metadata...*')
await tiktok(url)
.then((videoMeta) => {
const filename = videoMeta.authorMeta.name + '.mp4'
const caps = `*Metadata:*\nUsername: ${videoMeta.authorMeta.name} \nMusic: ${videoMeta.musicMeta.musicName} \nView: ${videoMeta.playCount.toLocaleString()} \nLike: ${videoMeta.diggCount.toLocaleString()} \nComment: ${videoMeta.commentCount.toLocaleString()} \nShare: ${videoMeta.shareCount.toLocaleString()} \nCaption: ${videoMeta.text.trim() ? videoMeta.text : '-'} \n\nDonasi: kamu dapat membantuku beli dimsum dengan menyawer melalui https://saweria.co/donate/yogasakti atau mentrakteer melalui https://trakteer.id/red-emperor \nTerimakasih.`
client.sendFileFromUrl(from, videoMeta.url, filename, videoMeta.NoWaterMark ? caps : `⚠ Video tanpa watermark tidak tersedia. \n\n${caps}`, '', { headers: { 'User-Agent': 'okhttp/4.5.0' } })
.catch(err => console.log('Caught exception: ', err))
}).catch(() => {
client.reply(from, 'Gagal mengambil metadata, link yang kamu kirim tidak valid', id)
})
break
case '#ig':
if (args.length >= 2) {
var param = body.substring(body.indexOf(' '), body.length)
const resp = await get.get('https://villahollanda.com/api.php?url='+ param).json()
console.log(resp)
if (resp.mediatype == 'photo') {
var ext = '.png'
}else{
var ext = '.mp4'
}
client.sendFileFromUrl(from, resp.descriptionc, `igeh${ext}`)
}
break
case '#dujin':
if (args.length >= 2) {
var nuklir = args[1]
var dujin = 'https://kegma.herokuapp.com'
const resp = await get.get('https://kegma.herokuapp.com/doujinshi/'+ nuklir).json()
console.log(resp)
//const wk = resp.content.split('unduh/')[1].replace(/%20/g,' ').replace(/%C2%BB/g,'�').replace(/%3A/g,':')
if (resp.status) {
client.reply(from, `Result : ${dujin}${resp.content}`, message)
//client.sendFileFromUrl(from, `${dujin}${resp.content}`, `${nuklir}.pdf`)
//client.senFile(from, `C:\\Users\\administrator\\NApi\\pdf\\${wk}`, `${wk}`)
}else{
client.reply(from, 'Kode nuklir salah om', message)
}
}
break
case '#F':
if(isGroupMsg){
var asw = client.getGroupAdmins(from)
console.log(asw)
}
break
case '#lirik':
if(args.length >= 2){
const lagu = body.slice(7)
const result = await liriklagu(lagu)
client.sendText(from, result)
}else{
client.reply(from, 'usage:\n\n!lirik aku bukan boneka', message)
}
break
case '#weather':
if(args.length >= 2){
const kota = args[1]
const result = await weather(kota)
client.sendText(from, result)
}
break
case '#quotemaker':
arg = body.trim().split('|')
if (arg.length == 4) {
client.sendText(from, 'Tunggu yaa, sedang proses . . .')
const quotes = arg[1]
const author = arg[2]
const theme = arg[3]
const result = await quotemaker(quotes, author, theme)
client.sendFile(from, result, 'quotesmaker.jpg','neh...')
}
break
case '#linkGrup':
if(isGroupMsg){
try {
const inviteLink = await client.getGroupInviteLink(chat.id);
client.sendLinkWithAutoPreview(from, inviteLink, `\nLink group *${name}*`)
} catch {
client.reply(from, 'Sepertinya bot belum menjadi admin', message)
}
}else{
client.reply(from, 'Perintah ini hanya bisa di gunakan dalam grup', message)
}
break
case '#owner':
if(isGroupMsg){
var owner = from.split('-')[0]
client.sendText(from, `[${owner}]`)
}else{
client.reply(from, 'Perintah ini hanya bisa di gunakan dalam grup', message)
}
break
case '#getPic':
if(!isGroupMsg){
try{
var jnck = await client.getProfilePicFromServer(from)
client.sendFileFromUrl(from, jnck, `awok.jpg`)
} catch {
client.reply(from, 'Pp lu gada anying, di private atau gimana?', message)
}
}else{
try{
var jnck = await client.getProfilePicFromServer(from)
client.sendFileFromUrl(from, jnck, 'gblk.jpg')
} catch {
client.reply(from, 'Terjadi kesalahan, tidak dapat mengirimkan foto profile group', message)
}
}
break
case '#add':
if(isGroupMsg){
if(args.length >=2){
var wkwk = `${from.split('-')[0]}@c.us`
if(message.author == wkwk || message.author == '[email protected]'){
try {
org = args[1]
client.addParticipant(from,`${org}@c.us`)
} catch {
client.reply(from, `Tidak dapat menambahkan ${org} mungkin karena di private`, message)
}
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
}else{
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
case '#kick':
if(isGroupMsg){
if(args.length >=2){
var wkwk = `${from.split('-')[0]}@c.us`
if(message.author == wkwk || message.author == '[email protected]' ){
wong = body.split('@')[1] || args[1]
client.removeParticipant(from,`${wong}@c.us`)
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
}else{
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
/* case '#leave':
if(isGroupMsg){
client.sendText(from,'Sayonara')
client.leaveGroup(from)
}
break*/
case '#setName':
if(isGroupMsg){
if(args.length >= 2) {
var wkk = `${from.split('-')[0]}@c.us`
if(message.author == wkk || message.author == '[email protected]') {
try {
const subject = body.slice(9)
console.log(subject)
client.setGroupTitle(from, subject)
} catch {
client.reply(from, 'Terjadi Kesalahan, tidak dapat mengubah title group!', message)
}
} else {
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
} else {
client.reply(from, 'Fitur ini hanya bisa gunakan dalam grup', message)
}
break
case '#promote':
if(isGroupMsg){
if(args.length >=2){
var wkwk = `${from.split('-')[0]}@c.us`
if(message.author == wkwk || message.author == '[email protected]' ){
prom = body.split('@')[1] || args[1]
client.promoteParticipant(from,`${prom}@c.us`)
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
}else{
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
case '#demote':
if(isGroupMsg){
if(args.length >=2){
var wkwk = `${from.split('-')[0]}@c.us`
if(message.author == wkwk || message.author == '[email protected]' ){
demo = body.split('@')[1] || args[1]
client.demoteParticipant(from,`${demo}@c.us`)
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}
}else{
client.reply(from, 'Fitur ini hanya bisa di gunakan dalam grup', message)
}
break
case '#revLinkGrup':
if(isGroupMsg){
var wkk = `${from.split('-')[0]}@c.us`
if(message.author == wkk) {
try {
await client.revokeGroupInviteLink(chat.id);
//client.sendText(from, 'Tautan undangan berhasil di tarik')
} catch (e) {
client.reply(from, 'Sepertinya bot belum menjadi admin', message)
}
}else{
client.reply(from, 'Lu siapa ajg? fitur ini cuma buat owner grup', message)
}
}else{
client.reply(from, 'Perintah ini hanya bisa di gunakan dalam grup', message)
}
break
case '#join':
client.reply(from, 'Izin dulu sama wa.me/6281246114524 kalo mau invite bot di grup mu', message)
/*if (args.length >=2) {
const link = args[1]
const invite = link.replace('https://chat.whatsapp.com/', '')
if (link.match(/(https:\/\/chat.whatsapp.com)/gi)) {
const check = await client.inviteInfo(invite);
if (check) {
await client.joinGroupViaLink(invite)
client.reply(from, 'Otw join gan', message)
} else {
client.reply(from, 'Sepertinya link grup bermasalah', message)
}
} else {
client.reply(from, 'Ini link????', message)
}
}*/
break
case '#Waifu':
case '#waifu':
q8 = q2 = Math.floor(Math.random() * 98) + 10;
client.sendFileFromUrl(from, 'http://randomwaifu.altervista.org/images/00'+q8+'.png', 'Waifu.png', 'Korewa daredesu ka?')
break
case '#neko':
q2 = Math.floor(Math.random() * 900) + 300;
q3 = Math.floor(Math.random() * 900) + 300;
client.sendFileFromUrl(from, 'http://placekitten.com/'+q3+'/'+q2, 'neko.png','Neko ')
break
case '#pokemon':
q7 = Math.floor(Math.random() * 890) + 1;
client.sendFileFromUrl(from, 'https://assets.pokemon.com/assets/cms2/img/pokedex/full/'+q7+'.png','Pokemon.png',)
break
case '#wallpaper' :
q4 = Math.floor(Math.random() * 800) + 100;
client.sendFileFromUrl(from, 'https://wallpaperaccess.com/download/anime-'+q4,'Wallpaper.png','Here is your wallpaper')
break
case '#quote' :
case '#quotes' :
case '#Quote' :
client.sendText(from, quotedd())
break
case '#meme':
const response = await axios.get('https://meme-api.herokuapp.com/gimme/wholesomeanimemes');
const { postlink, title, subreddit, url, nsfw, spoiler } = response.data
await client.sendFileFromUrl(from, `${url}`, 'meme.jpg', `${title}`)
break
case '#fb':
if (args.length >=2) {
const urlvid = args[1]
const high = await fbvid.high(urlvid)
const low = await fbvid.low(urlvid)
if (high == "Either the video is deleted or it's not shared publicly!") {
client.sendFileFromUrl(from, low.url, "video.mp4", "SD Video successfully downloaded")
} else if (high !== "Either the video is deleted or it's not shared publicly!") {
client.sendFileFromUrl(from, high.url, "video.mp4", "HD Video successfully downloaded")
} else if (high == "Either the video is deleted or it's not shared publicly!" && low == "Either the video is deleted or it's not shared publicly!") {
client.reply(from,"The URL is invalid",message)
}
} else {
client.reply(from,"The format is !fb [URL Video]",message)
}
break
case '#menu':
client.sendText(from, `╔═══════════════
╠══✪〘 Commands 〙✪══
╠➥#sticker
╠➥#neko
╠➥#Pokemon
╠➥#wallpaper
╠➥#info
╠➥#quotes
╠➥#meme
╠➥#linkGrup
╠➥#join
╠➥#getPic
╠➥#lirik <optional>
║
╠✪〘 Downloader 〙✪═
╠➥#ytmp3 <link>
╠➥#ig <link>
║
╠✪〘 For owner group 〙✪═
╠➥#add 628xxxx
╠➥#kick <@tagmember>
╠➥#promote <@tagmember>
╠➥#demote <@tagadmin>
╠➥#setPic send image with caption
╠➥#revLinkGrup
║
╠✪〘 Donate :) 〙✪════
╠➥#donasi
╚═〘 Me Bot 〙`)
break
case '#info':
client.sendText(from, 'Ini adalah program sumber terbuka yang ditulis dalam Javascript. \n \nDengan menggunakan bot, Anda menyetujui Syarat dan Ketentuan kami \n \nSyarat dan ketentuan \n \nTeks dan nama pengguna whatsapp Anda akan disimpan di server kami selama bot aktif, data Anda akan dihapus ketika bot menjadi offline. Kami TIDAK menyimpan gambar, video, file audio dan dokumen yang Anda kirim. Kami tidak akan pernah meminta Anda untuk mendaftar atau meminta kata sandi, OTP, atau PIN Anda. \n \n Terima kasih, Selamat bersenang-senang!')
}
} else {
if (!isGroupMsg) console.log('[RECV]', color(time, 'yellow'), color(body, 'red'), color(pushname))
if (isGroupMsg) console.log('[RECV]', color(time, 'yellow'), color(body, 'red'), color(pushname), 'in', color(name))
}
} catch (err) {
console.log(color('[ERROR]', 'red'), err)
}
}
process.on('Something went wrong', function (err) {
console.log('Caught exception: ', err);
});
function color (text, color) {
switch (color) {
case 'red': return '\x1b[31m' + text + '\x1b[0m'
case 'yellow': return '\x1b[33m' + text + '\x1b[0m'
default: return '\x1b[32m' + text + '\x1b[0m' // default is green
}
}
startServer()