-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathhandler.js
1774 lines (1628 loc) · 90.7 KB
/
handler.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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Config
var config = {
botName: '🔹 𝙉 O T 🔹',
operator: ['6281515860089'],
prefix: process.env.prefix ? new RegExp('^' + process.env.prefix) : /^[°•π÷׶∆£¢€¥®™✓_=|~!?@#$%^&.\/\\©^]/,
downloadStatus: false, // Curi Status Orang :|
devMode: false, // true,
msg: {
notAdmin: '🔰 Maaf anda bukan admin grup',
notGroup: '👨👩👧👦 Fitur ini hanya bisa digunakan di grup',
notBotAdmin: '🔰 Bot belum menjadi admin grup',
notURL: '🌐 Tidak ada URL',
noMedia: '📷 Tidak ada Media',
noArgs: '❓ Tidak ada argumen',
noJid: '❓ Tidak ada @user yang disebut',
notAllowed: `❌ Fitur ini tidak bisa kamu gunakan`,
add: '➕ Menambahkan:\n',
remove: '➖ Mengeluarkan:\n',
promote: '🔰 Menambahkan:\n',
demote: '🙍♂️ Menurunkan:\n',
self: 'Kok aku?',
dev: '👨💻 Fitur masih dalam tahap pengembangan 🔧',
devOff: '🔧 Fitur dinonaktifkan oleh developer',
groupOff: '❌ Fitur dinonaktifkan untuk grup ini',
success: '✅ Sukses',
success: '❌ Gagal',
list: value => `- ${value}`,
listUser: user => `- @${user.replace(/^@?|@c.us$/, '')}`,
promoteEach: user => `- @${user} menjadi Admin 🔰`,
demoteEach: user => `- @${user} menjadi Member 🙍♂️`,
promoteFail: user => `- @${user} sudah menjadi Admin 🔰`,
demoteFail: user => `- @${user} sudah menjadi Member 🙍♂️`,
promoteFormat: (success, failed) => config.msg.promote + success.map(config.msg.promoteEach).join('\n') + '\n' + failed.length > 0 ? failed.map(config.msg.promoteFail).join('\n') : '',
demoteFormat: (success, failed) => config.msg.demote + success.map(config.msg.demoteEach).join('\n') + '\n' + failed.length > 0 ? failed.map(config.msg.demoteFail).join('\n') : '',
yt: (title, filesize) => `*${title}*\n\n💾 Filesize: ${filesize}`,
recommend: (prefix, command) => `Direkomendasikan pakai *${prefix + command}*`,
sizeExceed: size => `❌ Ukuran file melebihi batas yang ditentukan\n💾 Filesize: *${size}*\n📈 Limit: *${config.sizeLimit} MB*`,
waitConvert: (a, b, desc) => `⏱ Tunggu beberapa detik!\nSedang melakukan proses konversi *${a}* → *${b}*${desc ? `\n\n${desc.split('\n').map(v => `_${v}_`).join('\n')}` : ''}`,
broadcast: (sender, msg) => `📢 *BROADCAST* 📢\n_From: @${sender.id}_\n\n${msg}`,
error: e => `⚠ *ERROR* ⚠\n\n${e}`,
ytsearch: item => {
switch (item.type) {
case 'video':
return `
*${item.type}*
├> Judul: ${item.title}
├> Durasi: ${item.duration[0]} (${item.duration[1]})
├> Channel: ${item.author.name} ${item.author.verified ? item.author.verified == 'artist' ? '🎶' : '✅' : ''}
├> Link: ${item.link}
├> Deskripsi: ${item.description}
`.slice(1, -1)
case 'channel':
return `
*${item.type}*
├> Nama: ${item.title} ${item.verified ? item.verified == 'artist' ? '🎶' : '✅' : ''}
├> Jumlah Video: ${item.videoCount}
├> Subscriber: ${item.subscriberCount}
├> Link: ${item.link}
├> Deskripsi: ${item.description}
`.slice(1, -1)
}
}
},
iklan: [
'Anda butuh API? Sini aja:v https://st4rz.herokuapp.com (Iklan by https://wa.me/6285221100126)',
// 'Grup: https://chat.whatsapp.com/EN08hYxatxgJXdxo9dsART',
'Github: https://github.com/Nurutomo/nbot-wa',
'API: https://repl.it/@Nurutomo/MhankBarBar-Api',
],
stickerGIF: {
fps: 20, // Lumayan
quality: 50, // Buriq?
target: '1M',
duration: 15 // Detik (Durasi Maksimal)
},
sizeLimit: -Infinity, // Megabytes
API: {
mhankbarbar: {
url: 'https://mhankbarbar-api--nurutomo.repl.co',
ig: '/api/ig',
}
},
features: {
ytv: false,
yta: false
}
}
/* Modules List */
// Built-in Modules
const fs = require('fs')
const os = require('os')
const path = require('path')
const util = require('util')
const { Readable, Writable } = require('stream')
// Local Modules
delete require.cache[require.resolve('./src/database')]
delete require.cache[require.resolve('./src/event')]
const { GroupData } = require('./src/database')
const _event = require('./src/event')
const group = new GroupData()
const cmd = new _event()
cmd.prefix = config.prefix
// External Modules
const sharp = require('sharp')
const chalk = require('chalk')
const { JSDOM } = require('jsdom')
const fetch = require('node-fetch')
const FormData = require('form-data')
const tree = require('tree-node-cli')
const puppeteer = require('puppeteer')
const ffmpeg = require('fluent-ffmpeg')
const text2image = require('text2image')
const moment = require('moment-timezone')
const { fromBuffer } = require('file-type')
const { sizeFormatter } = require('human-readable')
const translate = require('google-translate-open-api')
const { decryptMedia, Client } = require('@open-wa/wa-automate')
// const = require('')
moment.tz.setDefault('Asia/Jakarta').locale('id')
const format = sizeFormatter({
std: 'JEDEC', // 'SI' (default) | 'IEC' | 'JEDEC'
decimalPlaces: 2,
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`,
})
// Internal Modules
const AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
// Variables
const ytIdRegex = /(?:http(?:s|):\/\/|)(?:(?:www\.|)youtube(?:\-nocookie|)\.com\/(?:watch\?.*(?:|\&)v=|embed\/|v\/)|youtu\.be\/)([-_0-9A-Za-z]{11})/
const chromeText = bgColor(color(`[${color('Ch', '#1DA462') + color('ro', '#DD5144') + color('me', '#FFCD46')}]`, '#4C8BF5'), '#112')
// Config After Modules
config.font = {
ttp: text2image.loadFont('Futura Bold Italic font')
}
module.exports = async function (client = new Client(), message) {
try {
let { body, type, id, from, to, t, sender, isGroupMsg, chat, caption, isMedia, mimetype, quotedMsg, quotedMsgObj, mentionedJidList, author } = message
if (sender && sender.isMe) from = to
if (config.downloadStatus && from.startsWith('status')) { // Curi status orang:v
let dir = path.join('./database/status/', (await client.getHostNumber()))
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true })
let filename = t + (sender ? `_${(sender.formattedName || sender.verifiedName || sender.pushname)}` : '') + '_' + author.replace('@c.us', '') + (sender && sender.pushname ? `_${sender.pushname}` : '')
filename = filename.replace(/[\\\/\:\*\?\"\<\>\|]/g, '_')
if (mimetype) { // Foto/Video?
fs.writeFile(path.join(dir, filename + mimetype.replace(/.*\//, '.')), (await decryptMedia(message)).toString('binary'), { encoding: 'binary' }, err => {
if (err) console.error(err)
})
if (caption) { // Cek Caption
fs.writeFile(path.join(dir, filename + '.txt'), caption, err => {
if (err) console.error(err)
})
}
} else { // Teks Biasa
let { textColor, backgroundColor, font } = message
textColor = textColor.toString(16)
backgroundColor = backgroundColor.toString(16)
fs.writeFile(path.join(dir, filename + '.txt'), `${body}\n${'-'.repeat(25)}\nText: #${textColor}\nBackground: #${backgroundColor}\nFont: ${font}`, err => {
if (err) console.error(err)
})
}
}
const { name, formattedTitle } = chat
let { pushname, verifiedName, formattedName } = sender || { pushname: null, verifiedName: null, formattedName: null }
pushname = pushname || verifiedName || formattedName // verifiedName is the name of someone who uses a business account
const botNumber = await client.getHostNumber() + '@c.us'
const groupId = isGroupMsg ? chat.id : ''
const groupAdmins = chat && chat.groupMetadata && chat.groupMetadata.participants ? chat.groupMetadata.participants.filter(user=>user.isAdmin||user.isSuperAdmin).map(user=>user.id) : []
const groupMembers = chat && chat.groupMetadata && chat.groupMetadata.participants ? chat.groupMetadata.participants.map(user=>user.id) : []
const isGroupAdmins = groupAdmins.includes(sender ? sender.id : '') || false
const isBotGroupAdmins = groupAdmins.includes(botNumber) || false
const isOperator = (sender ? config.operator.map(id => id.replace(/[^\d]/g, '') + '@c.us').includes(sender.id) || sender.isMe : false) || false
if (isGroupMsg) group.update(groupId, chat.groupMetadata)
body = (type === 'chat' && cmd.prefix.test(body)) ?
body :
(((type === 'image' || type === 'video') && caption) && cmd.prefix.test(caption)) ?
caption :
''
const isImage = /^image/.test(mimetype)
const isVideo = /^video/.test(mimetype)
const isQuotedImage = quotedMsgObj && /^image/.test(quotedMsgObj.mimetype)
const isQuotedVideo = quotedMsgObj && /^video/.test(quotedMsgObj.mimetype)
const isQuotedAudio = quotedMsgObj && /^audio/.test(quotedMsgObj.mimetype)
const isQuotedFile = quotedMsgObj && quotedMsgObj.type === 'document'
const isQuotedSticker = quotedMsgObj && quotedMsgObj.type === 'sticker'
let rawText = type === 'chat' ?
message.body :
(type === 'image' || type === 'video') && caption ?
message.caption : ''
if ((rawText||'').startsWith('> ') /* && sender.id == ownerNumber*/) {
console.log(sender.id, 'is trying to use the execute command')
let type = Function
if (/await/.test(rawText)) type = AsyncFunction
let func = new type('print', 'client', 'message', 'config', 'group', 'fetch', 'fs', 'cmd', 'require', 'ti', 'cmd2case', !/^return /.test(rawText.slice(2)) && rawText.slice(2).split('\n').length === 1 ? 'return ' + rawText.slice(2) : rawText.slice(2))
let output
try {
output = func((...args) => {
console.log(...args)
client.reply(from, util.format(...args), id)
}, client, message, config, group, fetch, fs, cmd, require, text2image, text => text.replace(/^(async function|function|async).+\(.+?\).+{/, `case 'command':`).replace(/this\.(text|url|args)/g, (_, text) => {
switch (text) {
case 'text':
return "args.join(' ')"
break
case 'args':
return "args"
break
case 'url':
return "args[0]"
break
case 'prefix':
return "prefix"
break
default: return _
}
}).replace(/}$/, ' break'))
console.log(output)
client.reply(from, '*Console Output*\n\n' + util.format(output), id)
} catch (e) {
client.reply(from, '*Console Error*\n\n' + util.format(e), id)
}
}
if (isGroupMsg) group.update(chat.id, chat.groupMetadata)
// cmd.middleware = (next, name) => {
// if (group.permission(groupId, sender.id, name)) next()
// else client.reply(from, config.msg.notAllowed)
// }
cmd.middleware = next => {
if (config.devMode && isOperator) next()
else if (!config.devMode) next()
}
cmd.check(body, true, client, {
...message,
pushname,
botNumber,
groupId,
groupAdmins,
groupMembers,
isGroupAdmins,
isBotGroupAdmins,
isOperator,
isImage,
isVideo,
isQuotedImage,
isQuotedVideo,
isQuotedAudio,
isQuotedFile,
isQuotedSticker,
rawText,
body,
message,
from,
to
}).then(data => {
let tipe = bgColor(color(type.replace(/^./, (str) => str.toUpperCase()) + (from.startsWith('status') ? ' Status' : ''), 'black'), 'yellow')
if (data.known) {
if (data.pass) {
if (!isGroupMsg && sender && sender.isMe) console.log(color('[EXEC]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`), 'from', color(pushname), 'in', color(name || formattedTitle))
else if (!isGroupMsg) console.log(color('[EXEC]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`), 'from', color(pushname))
else if (isGroupMsg) console.log(color('[EXEC]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`), 'from', color(pushname), 'in', color(name || formattedTitle))
} else {
if (!isGroupMsg && sender && sender.isMe) console.log(color('[????]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`, 'red'), 'from', color(pushname), 'in', color(name || formattedTitle))
else if (!isGroupMsg) console.log(color('[????]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`, 'red'), 'from', color(pushname))
else if (isGroupMsg) console.log(color('[????]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${cmd.command} [${cmd.args.length}]`, 'red'), 'from', color(pushname), 'in', color(name || formattedTitle))
}
} else {
if (!isGroupMsg && sender && sender.isMe) console.log('[RECV]', color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), `${tipe} from`, color(pushname)), 'in', color(name || formattedTitle)
else if (!isGroupMsg && message.ack < 0) console.log('[RECV]', color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), `${tipe} from`, color(pushname))
else if (isGroupMsg && message.ack < 0) console.log('[RECV]', color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), `${tipe} from`, color(pushname), 'in', color(name || formattedTitle))
}
}).catch(e => {
_err(e)
if (e.usedPrefix) client.sendText(message.from, config.msg.error(util.format(e)))
})
} catch (e) {
_err(e)
}
}
cmd.on('help', ['menu', 'help', '?', 'tolong'], async function (client = new Client(), { from, id, pushname }) {
try {
client.reply(from, showHelp(this.usedPrefix, pushname, this.args[0]), id)
} catch (e) {
client.sendText(from, showHelp(this.usedPrefix, pushname, this.args[0]))
_err(e)
}
})
cmd.on('sticker', /^sti(c|)ker$/i, async function (client = new Client(), { from, id, isImage, isQuotedImage, isQuotedFile, quotedMsg, message }) {
if (isImage || isQuotedImage || isQuotedFile) {
const encryptMedia = isQuotedImage || isQuotedFile ? quotedMsg : message
const _mimetype = encryptMedia.mimetype
const mediaData = await decryptMedia(encryptMedia)
if (_mimetype === 'image/webp') client.sendRawWebpAsSticker(from, mediaData.toString('base64'), false)
const sticker = await processSticker(mediaData, 'contain')
await client.sendRawWebpAsSticker(from, sticker.toString('base64'), false)
} else client.reply(from, config.msg.noMedia, id)
})
cmd.on('meme', 'meme', async function (client = new Client(), { from, id, isImage, isQuotedImage, quotedMsg, message }) {
if (isImage || isQuotedImage) {
let top = ''
let bottom = this.text
if (/\|/.test(this.text)) {
[top, bottom] = this.text.split('|')
}
const encryptMedia = isQuotedImage ? quotedMsg : message
const mediaData = await decryptMedia(encryptMedia)
const getUrl = await uploadImages(mediaData, false)
const ImageBase64 = await customText(getUrl, top, bottom)
client.sendFile(from, ImageBase64, 'image.png', '', null, true)
.then((serialized) => console.log(`Sukses Mengirim File dengan id: ${serialized}`))
} else client.reply(from, config.msg.noMedia, id)
})
cmd.on('memesticker', /^(memesti(c|)ker|sti(c|)kermeme)$/i, async function (client = new Client(), { from, id, isImage, isQuotedImage, quotedMsg, message }) {
if (isImage || isQuotedImage) {
let top = ''
let bottom = this.text
if (/\|/.test(this.text)) {
[top, bottom] = this.text.split('|')
}
const encryptMedia = isQuotedImage ? quotedMsg : message
const mediaData = await decryptMedia(encryptMedia)
const getUrl = await uploadImages(mediaData, false)
const ImageBase64 = await customText(getUrl, top, bottom)
const stiker = await processSticker(ImageBase64, 'contain')
client.sendRawWebpAsSticker(from, stiker.toString('base64'), false)
} else client.reply(from, config.msg.noMedia, id)
})
cmd.on('sgif', /^(sti(c|)kergif|gifsti(c|)ker|sgif)$/i, async function (client = new Client(), { from, id, isMedia, isQuotedVideo, isQuotedFile, quotedMsg, message, isOperator }) {
if (!isOperator) return client.reply(from, 'Dh lh rusak lagi :(', id)
if ((isMedia || isQuotedVideo || isQuotedFile) && this.args.length === 0) {
const encryptMedia = isQuotedVideo || isQuotedFile ? quotedMsg : message
const mimetype = encryptMedia.mimetype
client.reply(from, config.msg.waitConvert(mimetype.replace(/.+\//, ''), 'webp', 'Stiker itu pakai format *webp*'), id)
if (/image/.test(mimetype)) client.reply(from, config.msg.recommend(this.usedPrefix, 'stiker'), id)
console.log(color('[WAPI]'), 'Downloading and decrypting media...')
const mediaData = await decryptMedia(encryptMedia)
if (mimetype === 'image/webp') client.sendRawWebpAsSticker(from, mediaData.toString('base64'), true)
const pathFormat = {
name: new Date() * 1,
ext: mimetype.replace(/.+\//, '.'),
dir: path.resolve(path.join('temp', mimetype.replace(/\/.+/, '')))
}
const tempPath = path.format(pathFormat)
fs.mkdirSync(pathFormat.dir, { recursive: true })
fs.writeFileSync(tempPath, mediaData)
const sticker = await stream2Buffer(write => {
ffmpeg(tempPath)
.inputOptions([
'-t', config.stickerGIF.duration || '5'
])
.complexFilter([
(config.stickerGIF.fps >= 1 ? 'fps=' + config.stickerGIF.fps + ',' : '') + 'scale=512:512:flags=lanczos:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=#00000000,setsar=1'
])
.outputOptions([
'-qscale', config.stickerGIF.quality,
'-fs', config.stickerGIF.target || '1M',
'-loop', '0',
'-an',
'-vsync', '0'
])
.format('webp')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendRawWebpAsSticker(from, sticker.toString('base64'), true)
fs.unlinkSync(tempPath)
}
})
cmd.on('add', ['add', '+'], async function (client = new Client(), { from, id, isGroupMsg, isBotGroupAdmins, botNumber, groupId }) {
args = this.args.join(' ').split(',').map(number => number.trim())
failed = permission([
[!isGroupMsg, config.msg.notGroup],
// [!isGroupAdmins, config.msg.notAdmin],
[!isBotGroupAdmins, config.msg.notBotAdmin],
[this.args.length === 0, config.msg.noArgs],
[this.args.includes(botNumber.replace('@c.us', '')), config.msg.self],
])
if (failed[0]) return client.reply(from, failed[1], id)
await client.sendTextWithMentions(from, config.msg.add + args.map(config.msg.listUser).join('\n'))
for (let i = 0; i < args.length; i++) {
client.addParticipant(groupId, args[i] + '@c.us')
}
})
cmd.on('kick', ['kick', '-'], async function (client = new Client(), { from, id, isGroupMsg, isGroupAdmins, isBotGroupAdmins, botNumber, groupId, mentionedJidList }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[!isGroupAdmins, config.msg.notAdmin],
[!isBotGroupAdmins, config.msg.notBotAdmin],
[mentionedJidList.length === 0, config.msg.noArgs],
[mentionedJidList.includes(botNumber), config.msg.self],
])
if (failed[0]) return client.reply(from, failed[1], id)
await client.sendTextWithMentions(from, config.msg.remove + this.args.map(config.msg.listUser).join('\n'))
for (let i = 0; i < mentionedJidList.length; i++) {
client.removeParticipant(groupId, mentionedJidList[i] + '@c.us')
}
})
cmd.on('promote', ['promote', '^'], async function (client = new Client(), { from, id, isGroupMsg, isGroupAdmins, isBotGroupAdmins, mentionedJidList, groupMembers, groupAdmins, groupId, botNumber }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[!isGroupAdmins, config.msg.notAdmin],
[!isBotGroupAdmins, config.msg.notBotAdmin],
])
if (failed[0]) return client.reply(from, failed[1], id)
if (this.args.length > 0 && this.args[0] == '@a') mentionedJidList = groupMembers
else if (this.args.length > 0 && this.args[0] == '@r') mentionedJidList = pickRandom(groupMembers.filter(id => !groupAdmins.includes(id)))
failed = permission([
[mentionedJidList.length < 1, config.msg.noJid]
])
if (failed[0]) return client.reply(from, failed[1], id)
let successList = []
let failedList = []
for (let mentionid of mentionedJidList) {
if (groupAdmins.includes(mentionid) || mentionid === botNumber) {
failedList.push(mentionid)
continue
}
client.promoteParticipant(groupId, mentionid)
successList.push(mentionid)
// let success = await client.promoteParticipant(groupId, mentionid)
// if (success) successList.push(mentionid)
// else failedList.push('Maaf, Error')
}
client.sendTextWithMentions(from, config.msg.promoteFormat(successList, failedList))
})
cmd.on('demote', ['demote', 'v'], async function (client = new Client(), { from, id, isGroupMsg, isGroupAdmins, isBotGroupAdmins, mentionedJidList, groupMembers, groupAdmins, groupId, botNumber }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[!isGroupAdmins, config.msg.notAdmin],
[!isBotGroupAdmins, config.msg.notBotAdmin],
])
if (failed[0]) return client.reply(from, failed[1], id)
if (this.args.length > 0 && this.args[0] == '@a') mentionedJidList = groupAdmins
else if (this.args.length > 0 && this.args[0] == '@r') mentionedJidList = pickRandom(groupAdmins)
failed = permission([
[mentionedJidList.length < 1, config.msg.noJid]
])
if (failed[0]) return client.reply(from, failed[1], id)
let successList = [],
failedList = []
for (let mentionid of mentionedJidList) {
if (!groupAdmins.includes(mentionid) || mentionid === botNumber) {
failedList.push(mentionid)
continue
}
client.demoteParticipant(groupId, mentionid)
successList.push(mentionid)
// let success = await client.promoteParticipant(groupId, mentionid)
// if (success) successList.push(mentionid)
// else failedList.push('Maaf, Error')
}
client.sendTextWithMentions(from, config.msg.demoteFormat(successList, failedList))
})
cmd.on('resend', /^(re(send|post)|to(img|image))$/i, async function (client = new Client(), { from, id, quotedMsgObj }) {
if (quotedMsgObj) {
let encryptMedia
const replyOnReply = await client.getMessageById(quotedMsgObj.id)
const obj = replyOnReply.quotedMsgObj
if (/ptt|audio|video|image|document|sticker/.test(quotedMsgObj.type)) encryptMedia = quotedMsgObj
else if (obj && /ptt|audio|video|image/.test(obj.type)) encryptMedia = obj
else return
const _mimetype = encryptMedia.mimetype
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(encryptMedia)
if (encryptMedia.animated) {
client.reply(from, config.msg.waitConvert('webp', 'mp4', 'Kebalikan dari gifstiker'), id)
const sticker = await stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.format('mp4')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendRawWebpAsSticker(from, sticker.toString('base64'), true)
} else client.sendFile(from, baseURI(mediaData, _mimetype), `file.${_mimetype.replace(/.+\//, '')}`, ':)', encryptMedia.id)
} else client.reply(from, config.msg.noMedia, id)
})
cmd.on('ytv', /^yt((dl|)mp4|v)$/i, async function (client = new Client(), { from, id }) {
failed = permission([
[!this.url, config.msg.notURL]
])
if (failed[0]) return client.reply(from, failed[1], id)
let res = await ytv(this.url)
if (res.filesize > config.sizeLimit * 1000) return client.sendImage(from, res.thumb, 'thumbs.jpg', config.msg.yt(res.title, res.filesizeF) + '\n\nUse Link: ' + res.dl_link + '\n' + config.msg.sizeExceed(res.filesizeF), id)
client.sendImage(from, res.thumb, 'thumbs.jpg', config.msg.yt(res.title, res.filesizeF) + '\n' + res.dl_link, id)
client.sendFileFromUrl(from, res.dl_link, `media.${res.ext}`, config.msg.yt(res.title, res.filesizeF), id)
})
cmd.on('yta', /^yt((dl|)mp3|a)$/i, async function (client = new Client(), { from, id }) {
failed = permission([
[!this.url, config.msg.notURL]
])
if (failed[0]) return client.reply(from, failed[1], id)
let res = await yta(this.url)
if (res.filesize > config.sizeLimit * 1000) return client.sendImage(from, res.thumb, 'thumbs.jpg', config.msg.yt(res.title, res.filesizeF) + '\n\nUse Link: ' + res.dl_link + '\n' + config.msg.sizeExceed(res.filesizeF), id)
client.sendImage(from, res.thumb, 'thumbs.jpg', config.msg.yt(res.title, res.filesizeF) + '\n' + res.dl_link, id)
client.sendFileFromUrl(from, res.dl_link, `media.${res.ext}`, config.msg.yt(res.title, res.filesizeF), id)
})
cmd.on('ping', /^((bot|)stat(s|)|botinfo|infobot|ping|speed)$/i, async function (client = new Client(), { from, botNumber, t }) {
const loadedMsg = await client.getAmountOfLoadedMessages()
const chatIds = await client.getAllChatIds()
const groups = await client.getAllGroups()
const groupsIn = groups.filter(x => x.groupMetadata.participants.map(x => [botNumber, '[email protected]'].includes(x.id._serialized)).includes(true))
const me = await client.getMe()
const battery = await client.getBatteryLevel()
const isCharging = await client.getIsPlugged()
const used = process.memoryUsage()
const cpus = os.cpus().map(cpu => {
cpu.total = Object.keys(cpu.times).reduce((last, type) => last + cpu.times[type], 0)
return cpu
})
const cpu = cpus.reduce((last, cpu, _, { length }) => {
last.total += cpu.total
last.speed += cpu.speed / length
last.times.user += cpu.times.user
last.times.nice += cpu.times.nice
last.times.sys += cpu.times.sys
last.times.idle += cpu.times.idle
last.times.irq += cpu.times.irq
return last
}, {
speed: 0,
total: 0,
times: {
user: 0,
nice: 0,
sys: 0,
idle: 0,
irq: 0
}
})
const speed = moment() / 1000 - t
client.sendText(from, `
Merespon dalam ${speed} detik
💬 Status :
- *${loadedMsg}* Loaded Messages
- *${groups.length}* Group Chats
- *${groupsIn.length}* Groups Joined
- *${groups.length - groupsIn.length}* Groups Left
- *${chatIds.length - groups.length}* Personal Chats
- *${chatIds.length - groups.length - groupsIn.length}* Personal Chats Active
- *${chatIds.length}* Total Chats
- *${chatIds.length - groupsIn.length}* Total Chats Active
📱 *Phone Info* :
${monospace(`
🔋 Battery : ${battery}% ${isCharging ? '🔌 Charging...' : '⚡ Discharging'}
${Object.keys(me.phone).map(key => `${key} : ${me.phone[key]}`).join('\n')}
`.trim())}
💻 *Server Info* :
RAM: ${format(os.totalmem() - os.freemem())} / ${format(os.totalmem())}
_NodeJS Memory Usage_
${monospace(Object.keys(used).map(key => `${key} : ${format(used[key])}`).join('\n'))}
_Total CPU Usage_
${cpus[0].model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times).map(type => `- *${(type + '*').padEnd(6)}: ${(100 * cpu.times[type] / cpu.total).toFixed(2)}%`).join('\n')}
_CPU Core(s) Usage (${cpus.length} Core CPU)_
${cpus.map((cpu, i) => `${i + 1}. ${cpu.model.trim()} (${cpu.speed} MHZ)\n${Object.keys(cpu.times).map(type => `- *${(type + '*').padEnd(6)}: ${(100 * cpu.times[type] / cpu.total).toFixed(2)}%`).join('\n')}`).join('\n\n')}
`.trim())
})
cmd.on('nulis', /^(mager|)[nt]ulis$/i, async function (client = new Client(), { from, id, quotedMsgObj }) {
let text = this.text || (quotedMsgObj && quotedMsgObj.type == 'chat' ? quotedMsgObj.body : '')
failed = permission([
[!text, config.msg.noArgs]
])
if (failed[0]) return client.reply(from, failed[1], id)
let page = await nulis(text||formatName(text), 1)
client.sendFile(from, page, 'nulis.png', ':v', id)
})
cmd.on('ig', /^ig(dl|)$/i, async function (client = new Client(), { from, id }) {
failed = permission([
[!this.url, config.msg.notURL]
])
if (failed[0]) return client.reply(from, failed[1], id)
let res = await mhankbarbar('ig', '?url=' + encodeURIComponent(this.url))
let json = await res.json()
client.sendFile(from, json.result, 'ig', '', id)
})
cmd.on('source', 'source', async function (client = new Client(), { from, id }) {
client.sendLinkWithAutoPreview(from, 'https://github.com/Nurutomo/nbot-wa', 'Repository:\nhttps://github.com/Nurutomo/nbot-wa')
})
cmd.on('mp3', ['mp3', 'audio'], async function (client = new Client(), { from, id, isQuotedVideo, quotedMsg, message }) {
if (isQuotedVideo) {
client.reply(from, config.msg.waitConvert('mp4', 'mp3', 'Meng-ekstrak audio dari video'), id)
const encryptMedia = isQuotedVideo ? quotedMsg : message
const _mimetype = isQuotedVideo ? quotedMsg.mimetype : mimetype
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(encryptMedia)
const audio = stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.format('mp3')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendFile(from, baseURI(audio, 'audio/mp3'), 'bass_boosted.mp3', '', id)
} else if (this.text) {
let search = await ytsr(this.text)
let ss = await ssPage(search.link, 1000)
client.sendFile(from, ss, 'yt.png', `Menampilkan hasil untuk ${search.correctQuery ? `*${search.correctQuery}* atau telusuri _${search.query}_` : `*${search.query}*`}\n\n${search.items.map(config.msg.ytsearch).join('\n\n')}`, id)
}
})
cmd.on('ss', /^ss(s|)$/i, async function (client = new Client(), { from, id }) {
if (/\d/.test(this.args[0])) {
let page = await client.getPage()
let index = parseInt(this.args[0], 10)
await page.evaluate(index => new Store.OpenChat().openChat(Store.Chat._models.filter(t => !t.__x_isGroup)[index].__x_id._serialized), index)
}
let ss = await client.getSnapshot()
let pic = await client.sendImage(from, ss, 'screenshot.png', '', id, true)
setTimeout(() => {
client.deleteMessage(from, pic, false)
}, 20000)
})
cmd.on('fs', 'fs', async function (client = new Client(), { from, id }) {
client.sendText(from, monospace(tree(__dirname, {
exclude: [/node_modules/, /status/],
depth: 5
}).replace(/── (.+)/g, (_, group) => `── ${/\..+/.test(group) ? '📄' : '📁'} ${group}`)))
})
cmd.on('distord', ['distord', 'distorsi', 'earrape'], async function (client = new Client(), { from, id, isQuotedAudio, isQuotedVideo, quotedMsg, message }) {
if (isQuotedAudio || isQuotedVideo) {
const encryptMedia = isQuotedAudio || isQuotedVideo ? quotedMsg : message
const _mimetype = encryptMedia.mimetype
client.reply(from, config.msg.waitConvert(_mimetype.replace(/.+\//, ''), 'mp3', '⚠ WARNING ⚠\n🔇 Tau lah :v'), id)
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(encryptMedia)
const distord = await stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.audioFilter('aeval=sgn(val(ch))')
.format('mp3')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendFile(from, baseURI(distord, 'audio/mp3'), 'distorted.mp3', '', id)
} else if (isQuotedVideo) {
// // Bantuin ffmpeg nya :')
// // biar bisa video filter sama audio filter
client.reply(from, config.msg.waitConvert('mp4', 'mp4', '⚠ WARNING ⚠\n🔇 Tau lah :v'), id)
const encryptMedia = isQuotedVideo ? quotedMsg : message
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(encryptMedia)
const distord = await stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.complexFilter('scale=iw/2:ih/2,eq=saturation=100:contrast=10:brightness=0.3:gamma=10,noise=alls=100:allf=t,unsharp=5:5:1.25:5:5:1,eq=gamma_r=100:gamma=50,scale=iw/5:ih/5,scale=iw*4:ih*4,eq=brightness=-.1,unsharp=5:5:1.25:5:5:1')
.audioFilter('aeval=sgn(val(ch))')
.outputOptions(
'-codec:v', 'libx264',
'-crf', '32',
'-preset', 'veryfast'
)
.format('mp4')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendFile(from, baseURI(distord, 'video/mp4'), 'distorted.mp4', '', id)
}
})
cmd.on('ssweb', 'ssweb', async function (client = new Client(), { from, id }) {
if (this.url) {
try {
if (!/^file|^http(s|):\/\//.test(this.url)) url = 'https://' + this.url
else url = this.url
let ss = await ssPage(url, this.args[1])
client.sendImage(from, ss, 'screenshot.png', url, id)
} catch (e) {
client.reply(from, config.msg.error(e), id)
}
}
})
cmd.on('sswebf', 'sswebf', async function (client = new Client(), { from, id }) {
if (this.url) {
try {
if (!/^file|^http(s|):\/\//.test(this.url)) url = 'https://' + this.url
else url = this.url
let [ss] = await Promise.all([
ssPage(url, this.args[1], true),
// ssPage(url, this.args[1], true, true)
])
client.sendImage(from, ss, 'screenshot.png', url, id)
// client.sendFile(from, ssPDF, 'screenshot.pdf', url, id)
} catch (e) {
client.reply(from, config.msg.error(e), id)
}
}
})
cmd.on('google', 'google', async function (client = new Client(), { from, id }) {
if (this.url) {
try {
let url = 'https://google.com/search?q=' + encodeURIComponent(this.text)
let ss = await ssPage(url, 1000, false)
await client.sendImage(from, ss, 'screenshot.png', url, id)
// await client.sendImage(from, ssFull, 'screenshot.png', url, id)
// client.sendFile(from, ssPDF, 'screenshot.pdf', url, id)
} catch (e) {
client.reply(from, config.msg.error(e), id)
}
}
})
cmd.on('googlef', 'googlef', async function (client = new Client(), { from, id }) {
if (this.url) {
try {
let url = 'https://google.com/search?q=' + encodeURIComponent(this.text) + '&tbm=isch'
let ss = await ssPage(url, 1000, false)
await client.sendImage(from, ss, 'screenshot.png', url, id)
// await client.sendImage(from, ssFull, 'screenshot.png', url, id)
// client.sendFile(from, ssPDF, 'screenshot.pdf', url, id)
} catch (e) {
client.reply(from, config.msg.error(e), id)
}
}
})
cmd.on('style', /^style|gaya$/i, async function (client = new Client(), { from, id, quotedMsgObj }) {
let text = ''
switch (useQuoted(this.text, quotedMsgObj)) {
case !0:
text = await stylizeText(quotedMsgObj.body)
client.reply(from, Object.keys(text).map(name => `*${name}*\n${text[name]}`).join('\n\n'), id)
break
case !1:
text = await stylizeText(this.text)
client.sendText(from, Object.keys(text).map(name => `*${name}*\n${text[name]}`).join('\n\n'))
break
default:
client.reply(from, config.msg.noArgs, id)
}
})
cmd.on('bass', /^(bass(boost|)|fullbass)$/i, async function (client = new Client(), { from, id, quotedMsg, isQuotedAudio }) {
if (isQuotedAudio) {
let dB = 20
let freq = 60
if (this.args[0]) dB = clamp(parseInt(this.args[0]) || 20, 0, 50)
if (this.args[1]) freq = clamp(parseInt(this.args[1]) || 20, 20, 500)
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(quotedMsg)
const bass = await stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.audioFilter('equalizer=f=' + freq + ':width_type=o:width=2:g=' + dB)
.format('mp3')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
client.sendFile(from, baseURI(bass, 'audio/mp3'), 'bass_boosted.mp3', '', id)
}
})
cmd.on('setuserrole', 'setuserrole', async function (client = new Client(), { from, id, isGroupMsg, mentionedJidList }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[mentionedJidList.length < 1, config.msg.noJid]
])
if (failed[0]) return client.reply(from, failed[1], id)
let successList = []
let failedList = []
let users = /@(\d{5,15}) (\d+)/g.exec(this.text)
for (let [, user, role] of users) {
if (group.setMemberRole(groupId, user + '@c.us', role)) successList.push(user + '@c.us')
else failedList.push(user + '@c.us')
}
client.sendTextWithMentions(from, `Done:\n${successList.map(config.msg.listUser)}\n\nFailed:\n${failedList.map(config.msg.listUser)}`)
})
cmd.on('getuserrole', 'getuserrole', async function (client = new Client(), { from, id, isGroupMsg, mentionedJidList, groupId }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[mentionedJidList.length < 1, config.msg.noJid]
])
if (failed[0]) return client.reply(from, failed[1], id)
client.sendTextWithMentions(from, mentionedJidList.map(user => `@${user.replace('@c.us', '')} ${group.getRoleById(groupId, user)}`))
})
cmd.on('setrole', 'setrole', async function (client = new Client(), { from, id, isGroupMsg }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[this.args.length < 3, config.msg.noArgs]
])
if (failed[0]) return client.reply(from, failed[1], id)
if (this.args[1] === 'name') this.args[2] = this.args[2]
else if (this.args[1] === 'id') this.args[2] = parseInt(this.args[2])
else this.args[2] = !!this.args[2]
if (group.setRole(groupId, this.args[0], this.args[1], this.args.slice(2).join(' '))) client.reply(from, config.msg.success, id)
else client.reply(from, config.msg.failed, id)
})
cmd.on('rolelist', 'rolelist', async function (client = new Client(), { from, id, isGroupMsg, groupId }) {
failed = permission([
[!isGroupMsg, config.msg.notGroup]
])
if (failed[0]) return client.reply(from, failed[1], id)
client.sendText(from, group.data[groupId].roles.map(role => {
return `*${role.name}*\n${monospace(JSON.stringify(role.name, null, 1))}`
}).join('\n\n'))
})
cmd.on('broadcast', ['broadcast', 'bc'], async function (client = new Client(), { from, id, isOperator, sender }) {
failed = permission([
[!isOperator, config.msg.notAllowed]
])
if (failed[0]) return client.reply(from, failed[1], id)
if (Object.keys(group.data).filter(chatId => group.data[chatId].broadcast).length > 0) client.reply(from, `Mengirim broadcast ke ${Object.keys(group.data).filter(chatId => group.data[chatId].broadcast).length} grup...`, id)
else client.reply(from, 'Tidak ada penerima', id)
broadcast(client, sender, this.text)
})
cmd.on('allowbroadcast', /^allowb(roadcast|c)$/i, async function (client = new Client(), { from, id, isGroupMsg, isGroupAdmins, isOperator, groupId }) {
if (!isOperator) {
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[!isGroupAdmins, config.msg.notAdmin]
])
if (failed[0]) return client.reply(from, failed[1], id)
}
bool = /^(y|ya|yes|enable|activate|true|1)$/i.test(this.args[0])
group.setAllowBroadcast(groupId, bool)
client.reply(from, `Allow receive broadcast from bot to this group is now set to *${bool ? 'en' : 'dis'}abled*`, id)
})
cmd.on('ttsticker', /^(t2s|tt?stic?ker|ttp)$/i, async function (client = new Client(), { from, id, quotedMsgObj }) {
let text = this.text || (quotedMsgObj ? quotedMsgObj.body : '')
failed = permission([
[!text, config.msg.noArgs]
])
if (failed[0]) return client.reply(from, failed[1], id)
let imgText = await text2image.convert(config.font.ttp, (text||formatName(text)).slice(0, 50), 0, 0, 512, {
attr: 'fill="#fff"',
align: 'center'
})
let sticker = await processSticker(imgText)
client.sendRawWebpAsSticker(from, baseURI(sticker.toString('base64'), 'image/webp'))
})
cmd.on('keylist', 'keylist', async function (client = new Client(), { from, id }) {
client.reply(from, `List:\n${Object.keys(this._events).join('\n')}`, id)
})
cmd.on('test', 'test', function (client = new Client(), { from, id }) {
// client.sendText('[email protected]', util.format(_, o))
console.log(formatName(this.text))
// client.reply(from, formatName(this.text), id)
})
cmd.on('ytsr', /^((yt|youtube)(search|sr)|lagu|musik|nyanyi|sing|song|play)$/, async function (client = new Client(), { from, id }) {
const search = await ytsr(this.text)
const ss = await ssPage(search.link, 1000)
client.sendFile(from, ss, 'yt.png', `Menampilkan hasil untuk ${search.correctQuery ? `*${search.correctQuery}* atau telusuri _${search.query}_` : `*${search.query}*`}\n\n${search.items.map(config.msg.ytsearch).join('\n\n')}`, id)
})
cmd.on('deepfry', ['deepfry', 'goreng'], async function (client = new Client(), { from, id, isImage, isQuotedImage, isQuotedSticker, quotedMsg, message }) {
if (isImage || isQuotedImage || isQuotedSticker) {
if (isQuotedSticker) client.reply(from, config.msg.waitConvert('webp (jpg 3x)', 'webp (jpg 3x)', 'Sedang menggoreng stiker:v (4 kali)'), id)
else client.reply(from, config.msg.waitConvert('jpg', 'jpg', 'Sedang menggoreng:v (4 kali)'), id)
const encryptMedia = !isImage && (isQuotedImage || isQuotedSticker) ? quotedMsg : message
console.log(color('[WAPI]', 'green'), 'Downloading and decrypt media...')
const mediaData = await decryptMedia(encryptMedia)
// .complexFilter('eq=saturation=100:contrast=10:brightness=0.1:gamma=10,noise=alls=60:allf=t,unsharp=5:5:1.25:5:5:1,eq=gamma_r=100')
const filter = 'eq=saturation=100,unsharp=5:5:1.25:5:5:1.0,noise=alls=40:allf=t'
const quality = '20'
let fry = await stream2Buffer(write => {
ffmpeg(buffer2Stream(mediaData))
.complexFilter(filter + ',scale=iw/2:ih/2')
.outputOptions('-q:v', quality)
.format('mjpeg')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
fry = await stream2Buffer(write => {
ffmpeg(buffer2Stream(fry))
.complexFilter(filter + ',scale=iw/2:ih/2')
.outputOptions('-q:v', quality)
.format('mjpeg')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
fry = await stream2Buffer(write => {
ffmpeg(buffer2Stream(fry))
.complexFilter(filter)
.outputOptions('-q:v', quality)
.format('mjpeg')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
fry = await stream2Buffer(write => {
ffmpeg(buffer2Stream(fry))
.complexFilter(filter)
.outputOptions('-q:v', quality)
.format('mjpeg')
.on('start', commandLine => console.log(color('[FFmpeg]'), commandLine))
.on('progress', progress => console.log(color('[FFmpeg]'), progress))
.on('end', () => console.log(color('[FFmpeg]'), 'Processing finished!'))
.stream(write)
})
if (isQuotedSticker) {
fry = await processSticker(fry, 'contain')
client.sendRawWebpAsSticker(from, fry.toString('base64'))
}
else client.sendFile(from, baseURI(fry, 'image/jpg'), 'deepfry.jpg', 'Nih gorengannya (deepfry)', id)
} else client.reply(from, config.msg.noMedia, id)
})
cmd.on('random', ['random', 'rng', 'dice', 'acak'], async function (client = new Client(), { from, id }) {
let min = this.args.length > 1 ? parseFloat(this.args[0]) : 1
let max = this.args.length > 1 ? parseFloat(this.args[1]) : 12
if (min > max) [min, max] = [max, min]
let rng = Math.floor(Math.random() * (max - min + 1))
client.reply(from, `🎲 ${rng}\nRange: ${min} - ${max}`, id)
})
cmd.on('freeup', ['freeup', 'cutcache', 'cutmsgcache'], async function (client = new Client(), { from, id, isOperator }) {
failed = permission([
[!isOperator, config.msg.notAllowed]
])
if (failed[0]) return client.reply(from, failed[1], id)
let before = await client.getAmountOfLoadedMessages()
await client.cutMsgCache()
let after = await client.getAmountOfLoadedMessages()
client.reply(from, `*Message Cache Cutted*\n_RAM Free Up_\n\nBefore: ${before} Messages\nAfter: ${after} Messages`, id)
})
cmd.on('title', ['title', 'settitle', 'judul', 'ubahjudul'], async function (client = new Client(), { from, id, isGroupMsg, isGroupAdmins, isBotGroupAdmins, groupId, chat }) {
this.text = this.text.slice(0, 25)
failed = permission([
[!isGroupMsg, config.msg.notGroup],
[!isGroupAdmins, config.msg.notAdmin],
[!isBotGroupAdmins, config.msg.notBotAdmin],
[!cmd.text, config.msg.noArgs],
])
if (failed[0]) return client.reply(from, failed[1], id)
let before = chat.groupMetadata.formattedTitle
let page = global.page ? global.page : await client.getPage()
await page.evaluate((chatId, subject) => Store.WapQuery.changeSubject(chatId, subject), groupId, cmd.text)