forked from dngda/bot-whatsapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandleMsg.js
3284 lines (3085 loc) · 182 KB
/
HandleMsg.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
/**
* @ Author: SeroBot Team
* @ Create Time: 2021-02-01 19:29:50
* @ Modified by: Danang Dwiyoga A (https://github.com/dngda/)
* @ Modified time: 2021-08-04 00:16:16
* @ Description: Handling message
*/
/* #region Import */
import { removeBackgroundFromImageBase64 } from 'remove.bg'
import { decryptMedia, Client } from '@open-wa/wa-automate'
import { exec, spawn } from 'child_process'
import { scheduleJob } from 'node-schedule'
// eslint-disable-next-line no-unused-vars
import { translate } from 'free-translate'
import moment from 'moment-timezone'
import appRoot from 'app-root-path'
import Ffmpeg from 'fluent-ffmpeg'
import { evaluate } from 'mathjs'
import toPdf from 'office-to-pdf'
import { inspect } from 'util'
import fetch from 'node-fetch'
import ytdl from 'ytdl-core'
import Crypto from 'crypto'
import jimp from 'jimp'
import fs from 'fs-extra'
import https from 'https'
import axios from 'axios'
import gTTS from 'gtts'
//Common-Js
const { existsSync, writeFileSync, readdirSync, readFileSync, writeFile, unlinkSync, createWriteStream } = fs
const { get } = axios
const { read } = jimp
/* #endregion */
/* #region LowDb */
import { LowSync, JSONFileSync } from 'lowdb'
import lodash from 'lodash'
const { sample, sampleSize } = lodash
const adapter = new JSONFileSync(appRoot + '/data/denda.json')
const db = new LowSync(adapter)
db.read()
db.data || (db.data = { groups: [] })
db.write()
db.chain = lodash.chain(db.data)
/* #endregion */
/* #region File Modules */
import {
createReadFileSync, processTime, commandLog, receivedLog, formatin, inArray, last,
unlinkIfExists, isFiltered, webpToPng, addFilter, isUrl, sleep, lolApi, prev
} from './utils/index.js'
import { getLocationData, urlShortener, cariKasar, schedule, canvas, cekResi, tebak, scraper, menuId, sewa, list, note, api } from './lib/index.js'
import { uploadImages } from './utils/fetcher.js'
import { cariNsfw } from './lib/kataKotor.js'
/* #endregion */
/* #region Load user data */
if (!existsSync('./data/stat.json')) {
writeFileSync('./data/stat.json', `{ "todayHits" : 0, "received" : 0 }`)
}
// settings
// eslint-disable-next-line no-unused-vars
let { stickerHash, ownerNumber, memberLimit, groupLimit, prefix, groupOfc } = JSON.parse(readFileSync('./settings/setting.json'))
const { apiNoBg } = JSON.parse(readFileSync('./settings/api.json'))
const kataKasar = JSON.parse(readFileSync('./settings/katakasar.json'))
// database
const banned = JSON.parse(createReadFileSync('./data/banned.json'))
const welcome = JSON.parse(createReadFileSync('./data/welcome.json'))
const antiKasar = JSON.parse(createReadFileSync('./data/ngegas.json'))
const antiKasarKick = JSON.parse(createReadFileSync('./data/ngegaskick.json'))
const antiLinkGroup = JSON.parse(createReadFileSync('./data/antilinkgroup.json'))
const antiLink = JSON.parse(createReadFileSync('./data/antilink.json'))
const antiVirtex = JSON.parse(createReadFileSync('./data/antivirtex.json'))
const antiDelete = JSON.parse(createReadFileSync('./data/antidelete.json'))
const disableBot = JSON.parse(createReadFileSync('./data/disablebot.json'))
const groupPrem = JSON.parse(createReadFileSync('./data/premiumgroup.json'))
const groupBanned = JSON.parse(createReadFileSync('./data/groupbanned.json'))
const ownerBotOnly = JSON.parse(createReadFileSync('./data/ownerbotonly.json'))
// src
const Surah = JSON.parse(readFileSync('./src/json/surah.json'))
const httpsAgent = new https.Agent({ rejectUnauthorized: false })
/* #endregion */
/* #region Helper functions */
moment.tz.setDefault('Asia/Jakarta').locale('id')
/* #endregion */
/* #region Stats */
let { todayHits, received } = JSON.parse(readFileSync('./data/stat.json'))
// Save stats in json every 5 minutes
scheduleJob('*/5 * * * *', () => {
receivedLog(received)
commandLog(todayHits)
})
// Reset today hits at 00:01
scheduleJob('1 0 * * *', () => {
received = 0
todayHits = 0
})
/* #endregion */
/* #region Main Function */
const HandleMsg = async (message, browser, client = new Client()) => {
received++ //Count msg received
/* #region Default response message */
const resMsg = {
wait: sample([
'⏳ Okey siap, sedang diproses!',
'⏳ Okey tenang tunggu bentar!',
'⏳ Okey, tunggu sebentar...',
'⏳ Shap, silakan tunggu!',
'⏳ Baiklah, sabar ya!',
'⏳ Sedang diproses!',
'⏳ Otw!'
]),
error: {
norm: '❌ Maaf, Ada yang error! Coba lagi beberapa menit kemudian.',
admin: '⛔ Perintah ini hanya untuk admin group!',
owner: '⛔ Perintah ini hanya untuk owner bot!',
group: `⛔ Maaf, perintah ini hanya dapat dipakai didalam group!${groupOfc ? `\nJoin sini ${groupOfc}` : ''}`,
botAdm: '⛔ Perintah ini hanya bisa di gunakan ketika bot menjadi admin',
join: '💣 Gagal! Sepertinya Bot pernah dikick dari group itu ya? Yah, Bot gabisa masuk lagi dong'
},
success: {
join: '✅ Berhasil join group via link!',
sticker: 'Here\'s your sticker 🎉',
greeting: `Hai guys 👋 perkenalkan saya SeroBot 🤖` +
`Untuk melihat perintah atau menu yang tersedia pada bot, kirim *${prefix}menu*. Tapi sebelumnya pahami dulu *${prefix}tnc*`
},
badw: sample([
'Capek saya mengcatat dosa Anda 😒',
'Yo rasah nggo misuh cuk! 😠',
'Jaga ketikanmu sahabat! 😉',
'Istighfar dulu sodaraku 😀',
'Ada masalah apasih? 🤔',
'Astaghfirullah...',
'Hadehh...'
])
}
/* #endregion */
try {
/* #region Variable Declarations */
if (message.body === '..' && message.quotedMsg && ['chat', 'image', 'video'].includes(message.quotedMsg.type)) {
// inject quotedMsg as Msg
let _t = message.t
message = message.quotedMsg
message.t = _t
}
let { body, type, id, from, t, sender, isGroupMsg, chat, chatId, caption, isMedia, mimetype, quotedMsg, quotedMsgObj, mentionedJidList, filehash } = message
var { name, formattedTitle } = chat
let { pushname, verifiedName, formattedName } = sender
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.groupMetadata.id : ''
const groupAdmins = isGroupMsg ? await client.getGroupAdmins(groupId) : ''
const pengirim = sender.id
const isBotGroupAdmin = groupAdmins.includes(botNumber) || false
const stickerMetadata = { pack: 'Created with', author: 'SeroBot', keepScale: true }
const stickerMetadataCircle = { pack: 'Created with', author: 'SeroBot', circle: true }
const stickerMetadataCrop = { pack: 'Created with', author: 'SeroBot', cropPosition: 'center' }
// Bot Prefix Aliases
const regex = /^[\\/!$^%&+.,-](?=\w+)/
let chats = '' // whole chats body
if (type === 'chat') chats = body
else chats = (type === 'image' && caption || type === 'video' && caption) ? caption : ''
prefix = regex.test(chats) ? chats.match(regex)[0] : '/'
body = chats.startsWith(prefix) ? chats : '' // whole chats body contain commands
const croppedChats = (chats?.length > 40) ? chats?.substring(0, 40) + '...' : chats
// sticker menu
for (let menu in stickerHash) {
if (filehash == stickerHash[menu]) body = `${prefix + menu}`, chats = body
}
// Respon to button
if (type === 'buttons_response') body = message.selectedButtonId, chats = body
if (prev.hasPrevCmd(pengirim)) {
body = `${prev.getPrevCmd(pengirim)} ${chats}`
prev.delPrevCmd(pengirim)
}
const command = body.trim().replace(prefix, '').split(/\s/).shift().toLowerCase()
const arg = body.trim().substring(body.indexOf(' ') + 1)
const arg1 = arg.trim().substring(arg.indexOf(' ') + 1)
const args = body.trim().split(/\s/).slice(1)
const sfx = readdirSync('./src/sfx/').map(item => {
return item.replace('.mp3', '')
})
/* #endregion */
client.sendSeen(chatId) // Read chat
/* #region Avoid Bug */
// Avoid order/vcard type msg (bug troli/slayer) gatau work apa kgk
if (type === 'order' || quotedMsg?.type === 'order' || type === 'vcard' || quotedMsg?.type === 'vcard') {
let _whenGroup = ''
if (isGroupMsg) _whenGroup = `in ${color(name || formattedTitle)}`
console.log(color('[ORDR]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(croppedChats, 'grey'), 'from', color(pushname), _whenGroup)
return client.deleteMessage(from, id, true)
}
// Avoid large body
if (chats?.length > 2500) {
let _whenGroup = ''
if (isGroupMsg) _whenGroup = `in ${color(name || formattedTitle)}`
console.log(color('[LARG]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(croppedChats, 'grey'), 'from', color(pushname), _whenGroup)
return client.deleteMessage(from, id, true)
}
const isAntiVirtex = antiVirtex.includes(chatId)
if (chats?.length > 10000 && isAntiVirtex) {
client.sendTextWithMentions(from, `💣 Member @${pengirim.replace(/@c\.us/, '')} terdeteksi mengirimkan pesan terlalu panjang! Auto kick!`)
client.removeParticipant(from, pengirim)
client.sendText(from, `💣 AWAS VIRTEX! TANDAI TELAH DIBACA 💣💣💣\n` + `\n`.repeat(200) + `Pengirim: ${pushname} -> ${pengirim}`)
}
/* #endregion */
/* #region [IDENTIFY] */
var isKasar = false
const isCmd = body.startsWith(prefix)
const isGroupAdmin = groupAdmins.includes(sender.id) || false
const isQuotedImage = quotedMsg?.type === 'image'
const isQuotedVideo = quotedMsg?.type === 'video'
const isQuotedChat = quotedMsg?.type === 'chat'
const isQuotedLocation = quotedMsg?.type === 'location'
const isQuotedDocs = quotedMsg?.type === 'document'
const isQuotedAudio = quotedMsg?.type === 'audio'
const isQuotedPtt = quotedMsg?.type === 'ptt'
const isQuotedSticker = quotedMsg?.type === 'sticker'
const isQuotedPng = isQuotedDocs && quotedMsg.filename.includes('.png')
const isQuotedWebp = isQuotedDocs && quotedMsg.filename.includes('.webp')
const isGroupOwnerBotOnly = ownerBotOnly.includes(chatId)
const isAntiLinkGroup = antiLinkGroup.includes(chatId)
const isAntiLink = antiLink.includes(chatId)
const isOwnerBot = ownerNumber.includes(pengirim)
const isBanned = banned.includes(pengirim)
const isNgegas = antiKasar.includes(chatId)
const isNgegasKick = antiKasarKick.includes(chatId)
const isDisabled = disableBot.includes(chatId)
const isWelcome = welcome.includes(chatId)
const isAntiDelete = antiDelete.includes(chatId)
/* #endregion */
if (isGroupOwnerBotOnly && !isOwnerBot) return null
/* #region Helper Functions */
const sendText = async (txt) => {
return client.sendText(from, txt)
.catch(e => {
console.log(e)
})
}
const reply = async (txt, qId = id) => {
return client.reply(from, txt, qId)
.catch(e => {
console.log(e)
})
}
const printError = (e, sendToOwner = true, sendError = true) => {
if (sendError) sendText(resMsg.error.norm)
let errMsg = `${e.name} ${e.message}`
let cropErr = errMsg.length > 100 ? errMsg.substr(0, 100) + '...' : errMsg
console.log(color('[ERR>]', 'red'), "{ " + croppedChats + " }\n", e)
if (sendToOwner) client.sendText(ownerNumber, `{ ${chats} }\n${cropErr}`)
return null
}
const sendFFU = async (url, capt = '', sendWait = true) => {
if (sendWait) sendText(resMsg.wait)
if (!capt) capt = ''
return client.sendFileFromUrl(from, url, '', capt, id)
.catch(e => { return printError(e) })
}
const sendSFU = async (url, sendWait = true) => {
if (sendWait) sendText(resMsg.wait)
return client.sendStickerfromUrl(from, url, null, stickerMetadata).then((r) => (!r && r != undefined)
? sendText('Maaf, link yang kamu kirim tidak memuat gambar.')
: sendText(resMsg.success.sticker)).then(() => console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`))
}
const sendJSON = (txt) => sendText(JSON.stringify(txt, null, 2))
// eslint-disable-next-line no-unused-vars
const sendJFU = async (url) => {
try {
let { data } = await get(url)
return data && sendJSON(data)
} catch (e) {
sendText(e.toString())
}
}
const audioConverter = async (complexFilter, filterName) => {
let durs = quotedMsg ? quotedMsg.duration : message.duration
reply(resMsg.wait + `\nEstimasi ± ${(+durs / 100).toFixed(0)} menit.`)
const _inp = await decryptMedia(quotedMsg)
let inpath = `./media/in_${filterName}_${t}.mp3`
let outpath = `./media/out_${filterName}_${t}.mp3`
writeFileSync(inpath, _inp)
Ffmpeg(inpath)
.setFfmpegPath('./bin/ffmpeg')
.complexFilter(complexFilter)
.on('error', (err) => {
console.log('An error occurred: ' + err.message)
if (filterName === 'custom') reply(err.message + '\nContohnya bisa dilihat disini https://www.vacing.com/ffmpeg_audio_filters/index.html')
else reply(resMsg.error.norm)
unlinkIfExists(inpath, outpath)
})
.on('end', () => {
client.sendFile(from, outpath, `${filterName}.mp3`, '', id)
.then(console.log(color('[LOGS]', 'grey'), `Audio Processed for ${processTime(t, moment())} Seconds`))
unlinkIfExists(inpath, outpath)
})
.saveToFile(outpath)
}
const startTebakRoomTimer = (seconds, answer) => {
const hint = answer.replace(/\s/g, '\t').replace(/[^aeiou\t]/gi, '_ ')
sleep(seconds * 1000 / 4).then(async () => {
const ans = await tebak.getAns(from)
if (ans === false) return true
else sendText(`⏳ ${((seconds * 1000) - (seconds * 1000 / 4 * 1)) / 1000} detik lagi`)
sleep(seconds * 1000 / 4).then(async () => {
const ans1 = await tebak.getAns(from)
if (ans1 === false) return true
else sendText(`⏳ ${((seconds * 1000) - (seconds * 1000 / 4 * 2)) / 1000} detik lagi\nHint: ${hint}`)
sleep(seconds * 1000 / 4).then(async () => {
const ans2 = await tebak.getAns(from)
if (ans2 === false) return true
else sendText(`⏳ ${((seconds * 1000) - (seconds * 1000 / 4 * 3)) / 1000} detik lagi`)
sleep(seconds * 1000 / 4).then(async () => {
const ans3 = await tebak.getAns(from)
if (ans3 === false) return true
else sendText(`⌛ Waktu habis!\nJawabannya adalah: *${answer}*`)
tebak.delRoom(from)
})
})
})
})
}
const doSimi = async (inp) => {
let apiSimi // set default simi di /utils/index.js
if (simi == 0) return null
if (simi == 1) apiSimi = (q) => api.simiLol(q)
if (simi == 2) apiSimi = (q) => api.simiPais(q)
if (simi == 3) apiSimi = (q) => api.simiZeks(q)
if (simi == 4) apiSimi = (q) => api.simiSumi(q)
let respon = await apiSimi(inp.replace(/\b(sero)\b/ig, 'simi')).catch(e => { return console.log(color('[ERR>]', 'red'), e) })
if (respon) {
console.log(color('[LOGS] Simi respond:', 'grey'), respon)
reply('▸ ' + respon.replace(/\b(simi|simsim|simsimi)\b/ig, 'sero'))
}
}
/* #endregion helper functions */
/* #region Command that banned people can access */
if (isCmd) {
// Typing
client.simulateTyping(chatId, true)
switch (command) {
case 'owner':
return await client.sendContact(from, ownerNumber)
.then(() => sendText('Jika ada pertanyaan tentang bot silakan chat nomor di atas ⬆\nChat tidak jelas akan diabaikan.'))
case 'rules':
case 'tnc':
return await sendText(menuId.textTnC())
case 'donate':
case 'donasi':
return await sendText(menuId.textDonasi())
default:
break
}
}
/* #endregion */
/* #region Enable or Disable bot */
if (isDisabled && command != 'enablebot') {
if (isCmd) sendText('⛔ DISABLED!')
if (isGroupAdmin && isCmd) sendText(`Kirim *${prefix}enablebot* untuk mengaktifkan!`)
return null
}
if (isCmd) {
client.simulateTyping(chatId, true)
switch (command) {
case 'enablebot': {
if (!isGroupMsg) return reply(resMsg.error.group)
if (!isGroupAdmin && !isOwnerBot) return reply(resMsg.error.admin)
let pos = disableBot.indexOf(chatId)
if (pos === -1) return reply('Bot memang masih aktif.')
disableBot.splice(pos, 1)
writeFileSync('./data/disablebot.json', JSON.stringify(disableBot))
return reply('✅ Bot untuk group diaktifkan kembali.')
}
case 'disablebot': {
if (!isGroupMsg) return reply(resMsg.error.group)
if (!isGroupAdmin && !isOwnerBot) return reply(resMsg.error.admin)
let pos = disableBot.indexOf(chatId)
if (pos != -1) return reply('Bot memang dimatikan.')
disableBot.push(chatId)
writeFileSync('./data/disablebot.json', JSON.stringify(disableBot))
return reply('❌ Bot untuk group dimatikan.')
}
default:
break
}
}
/* #endregion */
/* #region Filter banned people */
if (isBanned && !isGroupMsg && isCmd) {
return sendText(`Maaf anda telah dibanned oleh bot karena melanggar Rules atau Term and Condition (${prefix}tnc).\nSilakan chat /owner untuk unban.`).then(() => {
console.log(color('[BANd]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${command}[${args.length}]`), 'from', color(pushname))
})
}
else if (isBanned && isCmd) {
return console.log(color('[BANd]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'), color(`${command}[${args.length}]`), 'from', color(pushname), 'in', color(name || formattedTitle))
}
else if (isBanned) return null
/* #endregion Banned */
if ((isNgegas || isNgegasKick) && !isCmd) isKasar = await cariKasar(chats)
/* #region Spam and Logging */
if (isCmd && isFiltered(chatId)) {
let _whenGroup = ''
if (isGroupMsg) _whenGroup = `in ${color(name || formattedTitle)}`
console.log(color('[SPAM]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(`${command}[${args.length}]`), 'from', color(pushname), _whenGroup)
return reply('Mohon untuk perintah diberi jeda!')
}
// Spam cooldown
if (isFiltered(chatId + 'isCooldown')) {
if (isCmd) return reply(`Belum 1 menit`)
else return null
}
// Notify repetitive msg
if (chats != "" && isFiltered(chatId + croppedChats) && croppedChats != undefined) {
let _whenGroup = ''
if (isGroupMsg) _whenGroup = `in ${color(name || formattedTitle)}`
console.log(color('[SPAM]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(croppedChats, 'grey'), 'from', color(pushname), _whenGroup)
client.sendText(ownerNumber,
`Ada yang spam cuy:\n` +
`-> ${q3}GroupId :${q3} ${groupId}\n` +
`-> ${q3}GcName :${q3} ${isGroupMsg ? name || formattedTitle : 'none'}\n` +
`-> ${q3}Nomor :${q3} ${pengirim.replace('@c.us', '')}\n` +
`-> ${q3}Link :${q3} wa.me/${pengirim.replace('@c.us', '')}\n` +
`-> ${q3}Pname :${q3} ${pushname}\n\n` +
`-> ${croppedChats}`)
addFilter(chatId + 'isCooldown', 60000)
return reply(`SPAM detected!\nPesan selanjutnya akan diproses setelah 1 menit`)
}
// Avoid repetitive sender spam
if (isFiltered(pengirim) && !isCmd && chats != "") {
let _whenGroup = ''
if (isGroupMsg) _whenGroup = `in ${color(name || formattedTitle)}`
console.log(color('[SPAM]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(croppedChats, 'grey'), 'from', color(pushname), _whenGroup)
return null
}
// Avoid kata kasar spam
if (isFiltered(from) && isGroupMsg && isKasar) {
console.log(color('[SPAM]', 'red'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(`${command}[${args.length}]`), 'from', color(pushname), 'in', color(name || formattedTitle))
return reply('Mohon untuk tidak melakukan spam kata kasar!')
}
// Log Kata kasar
if (!isCmd && isKasar && isGroupMsg) {
console.log(color('[BADW]', 'orange'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
'from', color(pushname), 'in', color(name || formattedTitle))
}
// Log Commands
let argsLog = ''
if (args.length === 0) argsLog = color('with no args', 'grey')
else argsLog = (arg.length > 30) ? `${arg.substring(0, 30)}...` : arg
if (isCmd && !isGroupMsg) {
console.log(color('[EXEC]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(`${command}[${args.length}]`), ':', color(argsLog, 'magenta'), 'from', color(pushname))
}
if (isCmd && isGroupMsg) {
console.log(color('[EXEC]'), color(moment(t * 1000).format('DD/MM/YY HH:mm:ss'), 'yellow'),
color(`${command}[${args.length}]`), ':', color(argsLog, 'magenta'), 'from', color(pushname), 'in', color(name || formattedTitle))
}
//[BETA] Avoid Spam Message
if (isCmd) addFilter(chatId, 2000) // 2 sec delay before proessing commands
if (chats != "") addFilter(pengirim, 300) // 0.3 sec delay before receiving message from same sender
if (chats != "" && croppedChats != undefined) addFilter(chatId + croppedChats, 700) // 0.7 sec delay repetitive msg
/* #endregion Spam and Logging */
/* #region Handle default msg */
switch (true) {
case /^\b(hi|hy|halo|hai|hei|hello)\b/i.test(chats): {
await reply(`Halo ${pushname} 👋`)
break
}
case /^p$/i.test(chats): {
return !isGroupMsg ? sendText(`Untuk menampilkan menu, kirim pesan *${prefix}menu*`) : null
}
case /^(menu|start|help)$/i.test(chats): {
return await sendText(`Untuk menampilkan menu, kirim pesan *${prefix}menu*`)
}
case /assalamualaikum|assalamu'alaikum|asalamualaikum|assalamu'alaykum/i.test(chats): {
await reply('Wa\'alaikumussalam Wr. Wb.')
break
}
case /^=/.test(chats): {
try {
await reply(`${evaluate(chats.slice(1).replace(/x/ig, '*')
.replace(/×/g, '*').replace(/÷/g, '/').replace(/%/g, '/100'))}`)
} catch (e) {
reply(`${e.name} ${e.message}`)
}
break
}
case /\bping\b/i.test(chats): {
return await sendText(`Pong!!!\nSpeed: _${processTime(t, moment())} Seconds_`)
}
case new RegExp(`\\b(${sfx.join("|")})\\b`).test(chats?.toLowerCase()): {
const theSFX = chats?.toLowerCase().match(new RegExp(sfx.join("|")))
const path = `./src/sfx/${theSFX}.mp3`
const _id = (quotedMsg != null) ? quotedMsgObj.id : id
await client.sendPtt(from, path, _id).catch(e => { return printError(e) })
break
}
case /^#\S*$/ig.test(chats): {
let res = await note.getNoteData(from, chats.slice(1))
if (!res) return reply(`Note/catatan tidak ada, silakan buat dulu. \nGunakan perintah: *${prefix}createnote ${chats.slice(1)} (tulis isinya)* \nMohon hanya gunakan 1 kata untuk nama note`)
let respon = `✪〘 ${chats.slice(1).toUpperCase()} 〙✪`
respon += `\n\n${res.content}`
await reply(respon)
break
}
case /\b(bot|sero|serobot)\b/ig.test(chats): {
if (!isCmd) {
let txt = chats.replace(/@\d+/g, '')
return doSimi(txt)
}
break
}
case /^>/.test(chats): {
if (!isOwnerBot) return null
client.simulateTyping(from, false)
try {
let evaled = eval(`(async() => {
try {
${chats.slice(2)}
} catch (e) {
console.log(e)
sendText(e.toString())
}
})()`)
if (typeof evaled !== 'string') evaled = inspect(evaled)
if (chats.includes('return')) sendText(`${evaled}`)
else reply(`✅ OK!`)
} catch (err) {
console.log(err)
sendText(`${err}`)
}
break
}
case /^\$/.test(chats): {
if (!isOwnerBot) return null
client.simulateTyping(from, false)
exec(chats.slice(2), (err, stdout, stderr) => {
if (err) {
sendText(err)
console.error(err)
} else {
sendText(stdout + stderr)
console.log(stdout, stderr)
}
})
break
}
default:
}
// Jika bot dimention maka akan merespon pesan
if (message?.mentionedJidList?.length == 1 && message?.mentionedJidList?.includes(botNumber)) {
let txt = chats.replace(/@\d+/g, '')
if (txt.length === 0) {
reply(`Iya, ada apa?`)
} else {
doSimi(txt)
}
}
if (quotedMsg?.fromMe && !isCmd && type === `chat`) tebak.getAns(from).then(res => {
if (!res) return doSimi(chats)
})
/* #endregion */
/* #region Handle command message */
if (isCmd) {
todayHits++ // Command hits count
client.simulateTyping(chat.id, true)
switch (command) {
/* #region Menu, stats and info sewa*/
case 'menu':
case 'help':
case 'start': {
await sendText(menuId.textMenu(pushname, t, prefix))
if ((isGroupMsg) && (isGroupAdmin)) sendText(`Menu Admin Grup: *${prefix}menuadmin*`)
if (isOwnerBot) sendText(`Menu Owner: *${prefix}menuowner*`)
break
}
case 'menuadmin': {
if (!isGroupMsg) return reply(resMsg.error.group)
await sendText(menuId.textAdmin(prefix))
break
}
case 'menuowner': {
if (!isOwnerBot) return reply(resMsg.error.owner)
await sendText(menuId.textOwner(prefix))
break
}
case 'join':
case 'sewa': {
if (args.length == 0) return reply(
`Jika kalian ingin menculik bot ke group\n` +
`Silakan kontak owner atau gunakan perintah:\n` +
`-> ${prefix}join (link group) jika slot gratis masih tersedia.\n` //+
// `\nSlot gratis habis? Sewa aja murah kok.\n` +
// `Cuma 10k masa aktif 1 bulan.\n` +
// `Mau sewa otomatis? Gunakan link berikut:\n` +
// `Saweria: https://saweria.co/dngda \n` +
// `*Masukkan *hanya* link group kalian dalam kolom "Pesan" di website saweria*`
)
const linkGroup = args[0]
const isLinkGroup = linkGroup.match(/(https:\/\/chat\.whatsapp\.com)/gi)
if (!isLinkGroup) return reply('Maaf link group-nya salah! Silakan kirim link yang benar')
let groupInfo = await client.inviteInfo(linkGroup).catch(e => { return printError(e) })
if (groupBanned.includes(groupInfo.id)) return reply(`⛔ Group Banned`)
if (isOwnerBot) {
await client.joinGroupViaLink(linkGroup)
.then(async () => {
await sendText(resMsg.success.join)
if (args[1] != 'owneronly') {
setTimeout(async () => {
await client.sendText(groupInfo.id, resMsg.success.greeting)
}, 2000)
} else {
// silently join group with owneronly mode. Add 'owneronly' after grouplink
let pos = ownerBotOnly.indexOf(groupInfo.id)
if (pos == -1) {
ownerBotOnly.push(groupInfo.id)
writeFileSync('./data/ownerbotonly.json', JSON.stringify(ownerBotOnly))
}
}
}).catch(async () => {
return reply(resMsg.error.join)
})
} else {
let allGroup = await client.getAllGroups()
if (allGroup.length > groupLimit) return reply(
`Mohon maaf, untuk mencegah overload\n` +
`Slot group free pada bot dibatasi.\n` +
`Total group: ${allGroup.length}/${groupLimit}\n\n` +
`Chat /owner untuk sewa. Harga 10k masa aktif 1 bulan.\n` //+
// `Mau sewa otomatis? Gunakan link berikut:\n` +
// `Saweria: https://saweria.co/dngda \n` +
// `Masukkan hanya link group kalian dalam kolom *"Pesan"* di website saweria`
)
if (groupInfo?.size < memberLimit) return reply(`Maaf, Bot tidak akan masuk group yang anggotanya tidak lebih dari ${memberLimit} orang`)
reply(`⌛ Oke tunggu diproses sama owner ya!`)
client.sendText(ownerNumber, `Ada yang mau claim trial:\n` +
`${q3}Pushname :${q3} ${pushname}\n` +
`${q3}Pemohon :${q3} ${pengirim}\n` +
`${q3}GroupLink :${q3} ${args[0]}\n`
)
client.sendText(ownerNumber, `${prefix}trial ${pengirim} ${args[0]}`)
}
break
}
case 'trial': {
if (!isOwnerBot) return reply(resMsg.error.owner)
if (args.length != 2) return reply(`Format salah. Untuk claim trial gunakan.\n${prefix}trial <senderid> <linkg>`)
await sewa.trialSewa(client, args[1]).then(res => {
if (res) {
reply(`✅ Berhasil claim trial sewa bot selama 7 hari.`)
client.sendText(args[0], `✅ Berhasil claim trial sewa bot selama 7 hari.`)
}
else {
reply(`💣 Group sudah pernah claim trial. Tunggu habis dulu cuy!`)
client.sendText(args[0], `💣 Group sudah pernah claim trial. Tunggu habis dulu cuy!`)
}
}).catch(e => {
printError(e, true, false)
})
break
}
case 'stat':
case 'stats':
case 'status':
case 'botstat': {
let loadedMsg = await client.getAmountOfLoadedMessages()
let chatIds = await client.getAllChatIds()
let groups = await client.getAllGroups()
// eslint-disable-next-line no-undef
let time = process.uptime()
let uptime = (time + "").toDHms()
let statSewa = ''
if (isGroupMsg) {
let exp = sewa.getExp(from)
statSewa = (exp) ? `\n\nSewa expire at: _${exp.trim()}_` : ''
}
sendText(`Status :\n- *${loadedMsg}* Loaded Messages\n` +
`- *${groups.length}* Group Chats\n` +
`- *${chatIds.length - groups.length}* Personal Chats\n` +
`- *${chatIds.length}* Total Chats\n\n` +
`- *${todayHits}* Total Commands Today\n` +
`- *${received}* Total Received Msgs Today\n\n` +
`Speed: _${processTime(t, moment())} Seconds_\n` +
`Uptime: _${uptime}_ ${statSewa}`)
break
}
}
/* #endregion Menu, stats and info sewa */
switch (command) {
/* #region Sticker */
case 'getimage':
case 'stikertoimg':
case 'stickertoimg':
case 'toimg': {
if (isQuotedSticker) {
let mediaData = await decryptMedia(quotedMsg)
reply(resMsg.wait)
let imageBase64 = `data:${quotedMsg.mimetype};base64,${mediaData.toString('base64')}`
await client.sendFile(from, imageBase64, 'imgsticker.jpg', 'Berhasil convert Sticker to Image!', id)
.then(() => {
console.log(color('[LOGS]', 'grey'), `Sticker to Image Processed for ${processTime(t, moment())} Seconds`)
})
} else if (!quotedMsg) return reply(`Silakan tag/reply sticker yang ingin dijadikan gambar dengan command!`)
break
}
// Sticker Creator
case 'stickergif':
case 'stikergif':
case 'sticker':
case 'stiker':
case 's': {
if (
((isMedia && mimetype !== 'video/mp4') || isQuotedImage || isQuotedPng || isQuotedWebp)
&&
(args.length === 0 || args[0] === 'crop' || args[0] === 'circle' || args[0] !== 'nobg')
) {
reply(resMsg.wait)
try {
const encryptMedia = (isQuotedImage || isQuotedDocs) ? quotedMsg : message
let _metadata = null
if (args[0] === 'crop') _metadata = stickerMetadataCrop
else _metadata = (args[0] === 'circle') ? stickerMetadataCircle : stickerMetadata
let mediaData = await decryptMedia(encryptMedia).catch(e => printError(e, false))
if (mediaData) {
if (isQuotedWebp) {
await client.sendRawWebpAsSticker(from, mediaData.toString('base64'), true)
.then(() => {
sendText(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker from webp Processed for ${processTime(t, moment())} Seconds`)
}).catch(e => printError(e, false))
} else {
await client.sendImageAsSticker(from, mediaData, _metadata)
.then(() => {
sendText(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
}).catch(e => printError(e, false))
}
}
} catch (err) {
printError(err)
}
} else if (args[0] === 'nobg') {
if (isMedia || isQuotedImage) {
reply(resMsg.wait)
try {
let encryptedMedia = isQuotedImage ? quotedMsg : message
let _mimetype = isQuotedImage ? quotedMsg.mimetype : mimetype
let mediaData = await decryptMedia(encryptedMedia)
.catch(e => printError(e, false))
if (mediaData === undefined) return sendText(resMsg.error.norm)
let base64img = `data:${_mimetype};base64,${mediaData.toString('base64')}`
let outFile = './media/noBg.png'
// kamu dapat mengambil api key dari website remove.bg dan ubahnya difolder settings/api.json
let selectedApiNoBg = sample(apiNoBg)
let resultNoBg = await removeBackgroundFromImageBase64({ base64img, apiKey: selectedApiNoBg, size: 'auto', type: 'auto', outFile })
await writeFile(outFile, resultNoBg.base64img)
await client.sendImageAsSticker(from, `data:${_mimetype};base64,${resultNoBg.base64img}`, stickerMetadata)
.then(() => {
sendText(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker nobg Processed for ${processTime(t, moment())} Seconds`)
}).catch(e => printError(e, false))
} catch (err) {
console.log(color('[ERR>]', 'red'), err)
if (err[0].code === 'unknown_foreground') reply('Maaf batas objek dan background tidak jelas!')
else await reply('Maaf terjadi error atau batas penggunaan sudah tercapai!')
}
}
} else if (args.length === 1 && isUrl(args[0])) {
sendSFU(args[0], false)
} else if ((isMedia && mimetype === 'video/mp4') || isQuotedVideo) {
reply(resMsg.wait)
let encryptedMedia = isQuotedVideo ? quotedMsg : message
let mediaData = await decryptMedia(encryptedMedia)
.catch(e => printError(e, false))
await client.sendMp4AsSticker(from, mediaData, { endTime: '00:00:09.0' }, stickerMetadata)
.then(() => {
sendText(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
})
.catch(() => {
return reply('Maaf terjadi error atau filenya terlalu besar!')
})
} else {
await reply(`Tidak ada gambar/video!\n` +
`Untuk menggunakan ${prefix}sticker, kirim gambar/reply gambar atau *file png/webp* dengan caption\n` +
`*${prefix}sticker* (biasa uncrop)\n` +
`*${prefix}sticker crop* (square crop)\n` +
`*${prefix}sticker circle* (circle crop)\n` +
`*${prefix}sticker nobg* (tanpa background)\n\n` +
`Atau kirim pesan dengan\n` +
`*${prefix}sticker https://urlgambar*\n\n` +
`Untuk membuat *sticker animasi.* Kirim video/gif atau reply/quote video/gif dengan caption *${prefix}sticker* max 8 detik`)
}
break
}
case 'stikergiphy':
case 'stickergiphy': {
if (args.length != 1) return reply(`Maaf, format pesan salah.\nKetik pesan dengan ${prefix}stickergiphy <link_giphy> (don't include <> symbol)`)
const isGiphy = args[0].match(new RegExp(/https?:\/\/(www\.)?giphy.com/, 'gi'))
const isMediaGiphy = args[0].match(new RegExp(/https?:\/\/media\.giphy\.com\/media/, 'gi'))
if (isGiphy) {
const getGiphyCode = args[0].match(new RegExp(/(\/|-)(?:.(?!(\/|-)))+$/, 'gi'))
if (!getGiphyCode) { return reply('Gagal mengambil kode giphy') }
const giphyCode = getGiphyCode[0].replace(/[-/]/gi, '')
const smallGifUrl = 'https://media.giphy.com/media/' + giphyCode + '/giphy-downsized.gif'
client.sendGiphyAsSticker(from, smallGifUrl).then(() => {
reply(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
}).catch(e => { return printError(e) })
} else if (isMediaGiphy) {
const gifUrl = args[0].match(new RegExp(/(giphy|source).(gif|mp4)/, 'gi'))
if (!gifUrl) { return reply('Gagal mengambil kode giphy') }
const smallGifUrl = args[0].replace(gifUrl[0], 'giphy-downsized.gif')
client.sendGiphyAsSticker(from, smallGifUrl)
.then(() => {
reply(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
})
.catch(e => { return printError(e) })
} else {
await reply('Maaf, perintah sticker giphy hanya bisa menggunakan link dari giphy. [Giphy Only]')
}
break
}
case 'take':
case 'takestik':
case 'takesticker': {
if (!isQuotedSticker && args.length == 0) return reply(`Edit sticker pack dan author.\n${prefix}take packname|author`)
reply(resMsg.wait)
client.sendImageAsSticker(from, (await decryptMedia(quotedMsg)), {
pack: arg.split('|')[0],
author: arg.split('|')[1],
keepScale: true
}).then(() => {
reply(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
})
}
/* #endregion Sticker */
}
switch (command) {
/* #region Any Converter */
case 'shortlink': {
if (args.length == 0) return reply(`ketik ${prefix}shortlink <url>`)
if (!isUrl(args[0])) return reply('Maaf, url yang kamu kirim tidak valid. Pastikan menggunakan format http/https')
const shorted = await urlShortener(args[0])
await sendText(shorted).catch(e => { return printError(e) })
break
}
case 'hilih': {
if (args.length != 0 || isQuotedChat) {
const _input = isQuotedChat ? quotedMsg.body : arg
const _id = isQuotedChat ? quotedMsg.id : id
const _res = _input.replace(/[aiueo]/g, 'i')
reply(_res, _id)
const sUrl = api.memegen('https://memegenerator.net/img/images/11599566.jpg', '', _res)
client.sendFileFromUrl(from, sUrl, 'image.png', '', _id).catch(e => { return printError(e) })
}
else {
await reply(`Mengubah kalimat menjadi hilih gitu deh\n\nketik ${prefix}hilih kalimat\natau reply chat menggunakan ${prefix}hilih`)
}
break
}
case 'urltoimg':
case 'ssweb':
case 'gsearch':
case 'gs': {
if (args.length === 0) return reply(`Screenshot website atau search Google. ${prefix}ssweb <url> atau ${prefix}gs <query>`)
sendText(resMsg.wait)
let urlzz = ''
if (!isUrl(arg)) urlzz = `https://www.google.com/search?q=${encodeURIComponent(arg)}`
else urlzz = arg
const path = './media/ssweb.png'
scraper.ssweb(browser, path, urlzz).then(async res => {
if (res === true) await client.sendImage(from, path, 'ssweb.png', `Captured from ${urlzz}`, id).catch(e => { return printError(e) })
}).catch(e => { return printError(e) })
break
}
case 'qr':
case 'qrcode': {
if (args.length == 0) return reply(`Untuk membuat kode QR, ketik ${prefix}qrcode <kata>\nContoh: ${prefix}qrcode nama saya SeroBot`)
reply(resMsg.wait)
await client.sendFileFromUrl(from, `http://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(arg)}&size=500x500`, '', '', id)
break
}
case 'flip': {
if (!isMedia && args.length === 0 && !isQuotedImage) return reply(
`Flip gambar secara vertical atau horizontal. Kirim gambar dengan caption:\n` +
`${prefix}flip h -> untuk flip horizontal\n` +
`${prefix}flip v -> untuk flip vertical`)
const _enc = isQuotedImage ? quotedMsg : message
const _img = await decryptMedia(_enc).catch(e => { return printError(e) })
let image = await read(_img)
let path = './media/flipped.png'
if (args[0] === 'v') image.flip(false, true).write(path)
else if (args[0] === 'h') image.flip(true, false).write(path)
else return reply(`Argumen salah.\n` +
`${prefix}flip h -> untuk flip horizontal\n` +
`${prefix}flip v -> untuk flip vertical`)
await client.sendImage(from, path, '', '', id).catch(e => { return printError(e) })
break
}
case 'memefy': {
if ((isMedia || isQuotedImage || isQuotedSticker) && args.length >= 1) {
try {
if (quotedMsg?.isAnimated) return reply(`Error! Tidak support sticker bergerak.`)
reply(resMsg.wait)
let top = '', bottom = ''
if (!/\|/g.test(arg)) {
bottom = arg
} else {
top = arg.split('|')[0]
bottom = arg.split('|')[1]
}
let encryptMedia = (isQuotedImage || isQuotedSticker) ? quotedMsg : message
let mediaData = await decryptMedia(encryptMedia)
if (isQuotedSticker) mediaData = await webpToPng(mediaData)
let imgUrl = await uploadImages(mediaData, false)
let sUrl = api.memegen(imgUrl, top, bottom)
if (!isQuotedSticker) client.sendFileFromUrl(from, sUrl, 'image.png', 'Here you\'re', id).catch(e => { return printError(e) })
else await client.sendStickerfromUrl(from, sUrl, null, stickerMetadata)
.then(() => {
sendText(resMsg.success.sticker)
console.log(color('[LOGS]', 'grey'), `Sticker Processed for ${processTime(t, moment())} Seconds`)
}).catch(e => printError(e, false))
} catch (err) {
printError(err)
}
} else {
await reply(`Tidak ada gambar/format salah! Silakan kirim gambar dengan caption ${prefix}memefy <teks_atas> | <teks_bawah>\n` +
`Contoh: ${prefix}memefy ini teks atas | ini teks bawah`)
}
break
}
case 'ocr': {
if (!isMedia && !isQuotedImage) return reply(`Scan tulisan dari gambar. Reply gambar atau kirim gambar dengan caption ${prefix}ocr`)
try {
sendText(resMsg.wait)
let enc = isQuotedImage ? quotedMsg : message
let mediaData = await decryptMedia(enc)