This repository has been archived by the owner on Dec 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessageHandler.js
862 lines (731 loc) · 24.5 KB
/
messageHandler.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
const fs = require("fs");
const axios = require("axios");
const PDFDocument = require("pdfkit");
const request = require("request");
const teslang = require("./lib/lang");
const scrapy = require("node-scrapy");
const Genius = require("genius-lyrics");
const translate = require("translate-google");
const { Brainly } = require("brainly-scraper-v2");
const webpConverter = require("./lib/webpconverter");
const bahasa_planet = require("./lib/bahasa_planet");
const WSF = require("wa-sticker-formatter");
const { MessageType, Mimetype } = require("@adiwajshing/baileys");
const NLP = require("@hiyurigi/nlp")("TextCorrection");
const prefix = fs.readFileSync("./config/prefix.txt", "utf-8");
const factList = JSON.parse(fs.readFileSync("./lib/fact.json", "utf-8"));
const quotesList = JSON.parse(fs.readFileSync("./lib/quotes.json", "utf-8"));
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));
const { LatinKeAksara } = require("@sajenid/aksara.js");
const brain = new Brainly("id");
const { isNull } = require("util");
const bufferImagesForPdf = {};
const questionAnswer = {};
const inPdfInput = [];
const ytregex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
const Client = new Genius.Client("uO-XWa9PYgZn-t7UrNW_YTDlUrNCtMq8xmCxySRRGXP4QJ0mtFwoqi1z-ywdGmXj");
let v = new NLP([
'giftextsticker', 'stickernobg', 'textsticker',
'stikernobg', 'gifsticker', 'randomfact',
'kodebahasa', 'gifstiker', 'translate',
'wikipedia', 'contact', 'sticker',
'donatur', 'brainly', 'bplanet',
'lyrics', 'stiker', 'binary',
'aksara', 'quotes', 'cancel',
'lirik', 'ytmp3', 'gempa',
'snobg', 'toimg', 'togif',
'write', 'tulis', 'help',
'menu', 'gtts', 'kbbi',
'fact', 'math', 'done',
'pdf', 'bin', 'hex',
'yt', 'tl', 't',
]);
module.exports = async (conn, message) => {
const senderNumber = message.key.remoteJid;
const imageMessage = message.message.imageMessage;
const videoMessage = message.message.videoMessage;
const stickerMessage = message.message.stickerMessage;
const extendedTextMessage = message.message.extendedTextMessage;
const buttons = message.message.buttonsResponseMessage
const quotedMessageContext = extendedTextMessage && extendedTextMessage.contextInfo && extendedTextMessage.contextInfo;
const quotedMessage = quotedMessageContext && quotedMessageContext.quotedMessage;
let buttonMessages;
if (buttons != undefined) {
buttonMessages = buttons.selectedDisplayText
}
const textMessage = message.message.conversation || message.message.extendedTextMessage && message.message.extendedTextMessage.text || imageMessage && imageMessage.caption || videoMessage && videoMessage.caption || buttonMessages
const sender = conn.contacts[senderNumber]
let WAUser = sender?.notify || sender?.short || sender?.name || sender?.vname || conn?.user?.name
if (textMessage == '.menu') {
const buttons = [{
buttonId: 'id1',
buttonText: {
displayText: '!help'
},
type: 1
},
{
buttonId: 'id2',
buttonText: {
displayText: '!contact'
},
type: 1
}
]
const buttonMessage = {
contentText: `Halo selamat datang di *${conn.user.name}* silahkan gunakan *${prefix}help* untuk melihat perintah yang tersedia 😆`,
footerText: 'kamu juga bisa menekan tombol ini',
buttons: buttons,
headerType: 1
}
conn.sendMessage(senderNumber, buttonMessage, MessageType.buttonsMessage, {
quoted: message
});
}
let command, parameter;
if (textMessage) {
let a = textMessage.trim().split("\n");
let b = "";
c = a[0].split(" ")[0]
b += a[0].split(" ").slice(1).join(" ");
b += a.slice(1).join("\n")
parameter = b.trim();
pre = c.charAt(0);
d = c.substring(1);
if (pre == prefix) {
if (!d) {
let e = parameter.split(" ")
d = e[0];
parameter = parameter.split(" ").slice(1).join(" ");
}
if (d.toLowerCase() == "routes") {
command = "quotes";
} else {
let result = v.TextCorrection({
Needle: d,
Threshold: 0.7,
NgramsLength: 1
});
command = result[0].Key;
}
}
}
const stickerParameter = parameter || WAUser
if (inPdfInput.includes(senderNumber)) {
if (stickerMessage) return;
const buttons = [{
buttonId: 'id1',
buttonText: {
displayText: '!cancel'
},
type: 1
},
{
buttonId: 'id2',
buttonText: {
displayText: '!done'
},
type: 1
}
]
if (command == `done` || bufferImagesForPdf[senderNumber].length > 19) {
const pdf = new PDFDocument({
autoFirstPage: false
});
const bufferImages = bufferImagesForPdf[senderNumber];
for (const bufferImage of bufferImages) {
const image = pdf.openImage(bufferImage);
pdf.addPage({
size: [image.width, image.height]
});
pdf.image(image, 0, 0);
}
const pathFile = ".temp/" + Math.floor(Math.random() * 1000000 + 1) + ".pdf";
const file = fs.createWriteStream(pathFile);
pdf.pipe(file)
pdf.end()
file.on("finish", () => {
const file = fs.readFileSync(pathFile);
conn.sendMessage(senderNumber, file, MessageType.document, {
mimetype: Mimetype.pdf,
filename: Math.floor(Math.random() * 1000000) + ".pdf",
quoted: message
});
fs.unlinkSync(pathFile);
inPdfInput.splice(inPdfInput.indexOf(senderNumber), 1);
delete bufferImagesForPdf[senderNumber];
})
} else if (command == `cancel`) {
delete bufferImagesForPdf[senderNumber];
inPdfInput.splice(inPdfInput.indexOf(senderNumber), 1);
conn.sendMessage(senderNumber, "Operasi dibatalkan!", MessageType.text, {
quoted: message
})
} else if (imageMessage && imageMessage.mimetype == "image/jpeg") {
const bufferImage = await conn.downloadMediaMessage(message);
bufferImagesForPdf[senderNumber].push(bufferImage);
const buttonMessage = {
contentText: `Yay ${bufferImagesForPdf[senderNumber].length} gambar telah sukses ditambahkan\n\nKirim *${prefix}done* jika selesai, *!cancel* jika ingin membatalkan`,
footerText: `${conn.user.name} ${prefix}pdf`,
buttons: buttons,
headerType: 1
}
conn.sendMessage(senderNumber, buttonMessage, MessageType.buttonsMessage, {
quoted: message
});
} else {
const buttonMessage = {
contentText: `Ups maaf kirim gambar ya kak jangan stiker atau text 😊\n\nKirim *${prefix}done* jika selesai, *!cancel* jika ingin membatalkan`,
footerText: `${conn.user.name} ${prefix}pdf`,
buttons: buttons,
headerType: 1
}
conn.sendMessage(senderNumber, buttonMessage, MessageType.buttonsMessage, {
quoted: message
});
return;
}
}
switch (command) {
case `t`: {
let result = v.TextCorrection({
Needle: parameter,
Threshold: 0.4,
NgramsLength: 1
});
const text = result[0].Key;
console.log(result);
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `binary`:
case `bin`: {
const bin = parameter.split('').map(function (char) {
return char.charCodeAt(0).toString(2);
}).join(' ');
const text = `hasil konversi *${parameter}* ke Biner adalah\n\n*${bin}*`;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `hex`: {
let hexa = parameter.split('').map(function (char) {
return char.charCodeAt(0).toString(16);
}).join(' ');
const text = `hasil konversi *${parameter}* ke Hexadesimal adalah:\n\n*${hexa}*`
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `help`:
case `menu`: {
const text = fs.readFileSync("./config/menu.txt", 'utf-8');
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `contact`: {
const text = fs.readFileSync("./config/contact.txt", "utf-8");
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `donatur`: {
const text = fs.readFileSync("./config/donatur.txt", "utf-8");
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `kbbi`: {
const url = 'https://kbbi.kemdikbud.go.id/entri/';
const model = {
lema: 'h2',
arti: ['ol li', 'ul.adjusted-par'],
makna: 'ul.adjusted-par li'
}
fetch(url + encodeURIComponent(parameter)).then((res) => res.text()).then((body) => {
result = scrapy.extract(body, model);
let judul = ('arti kata *( ' + result.lema + ')* dalam KBBI adalah:\n\n');
let data = result.arti
if (data == null) {
const text = judul + result.makna;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
} else if (data != null) {
data.forEach((arr, i) => {
data[i] = (i + 1).toString() + ". " + arr
});
let isi = data.join('\n\n');
const text = judul + isi;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
} else {
conn.sendMessage(senderNumber, "maaf tidak ditemukan coba periksa ejaan atau coba kata lainnya", MessageType.text, {
quoted: message
});
};
});
break;
}
case `aksara`: {
if (quotedMessage) {
message.message = quotedMessage;
}
if (!parameter) {
conn.sendMessage(senderNumber, "Tidak ada text :)", MessageType.text, {
quoted: message
});
break;
}
let wada = LatinKeAksara(parameter);
const text = wada;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `sticker`:
case `stiker`: {
if (quotedMessage) {
message.message = quotedMessage;
}
if (!message.message.imageMessage || message.message.imageMessage.mimetype != "image/jpeg") {
conn.sendMessage(senderNumber, "Tidak ada gambar :)", MessageType.text, {
quoted: message
});
break;
}
const imagePath = await conn.downloadAndSaveMediaMessage(message, Math.floor(Math.random() * 1000000));
const sticker = new WSF.Sticker("./" + imagePath, {
crop: false,
pack: "Stiker",
author: stickerParameter
});
await sticker.build();
fs.unlinkSync(imagePath);
const bufferImage = await sticker.get();
conn.sendMessage(senderNumber, bufferImage, MessageType.sticker, {
quoted: message
});
break;
}
case "toimg": {
if (!quotedMessage || !quotedMessage.stickerMessage || quotedMessage.stickerMessage.mimetype != "image/webp") {
conn.sendMessage(senderNumber, "Ups, stikernya mana ya kak?", MessageType.text, {
quoted: message
});
break;
}
message.message = quotedMessage;
const webpImage = await conn.downloadMediaMessage(message);
const jpgImage = await webpConverter.webpToJpg(webpImage);
conn.sendMessage(senderNumber, jpgImage, MessageType.image, {
quoted: message,
caption: "Ini kak gamabrnya >///<"
});
break;
}
case `togif`: {
if (!quotedMessage || !quotedMessage.stickerMessage || quotedMessage.stickerMessage.mimetype != "image/webp") {
conn.sendMessage(senderNumber, "Ups, Gamabrnya mana ya kak?", MessageType.text, {
quoted: message
});
break;
}
message.message = quotedMessage;
const webpImage = await conn.downloadMediaMessage(message);
const video = await webpConverter.webpToVideo(webpImage);
conn.sendMessage(senderNumber, video, MessageType.video, {
quoted: message,
mimetype: Mimetype.gif
});
break;
}
case `write`:
case `nulis`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, {quoted: message})
break;
}
case `pdf`: {
if (message.participant) {
conn.sendMessage(senderNumber, "Maaf kak, demi menghindari spam fitur ini hanya tersedia di Private Chat", MessageType.text, {
quoted: message
});
break;
}
if (imageMessage) {
conn.sendMessage(senderNumber, "Ups kirim tanpa gambar ya kak", MessageType.text, {
quoted: message
});
break;
}
inPdfInput.push(senderNumber);
bufferImagesForPdf[senderNumber] = [];
conn.sendMessage(senderNumber, "Silahkan kirim gambarnya satu persatu! jangan spam ya!", MessageType.text, {
quoted: message
});
break;
}
case `brainly`: {
if (!parameter) {
conn.sendMessage(senderNumber, "Mau cari apa kak?, jangan lupa ya apa yang mau dicari ditulis juga", MessageType.text, {
quoted: message
});
break;
}
conn.sendMessage(senderNumber, "Sedang mencari jawabannya 🤨🔎", MessageType.text, { quoted: message })
brain.searchWithMT("id", parameter).then(res => {
let data = [];
for (let i = 0; i < res.length; i++) {
let soal = res[i].question.content;
let answer = res[i].answers[0].content;
data.push({
title: `*Soal:* ${soal}`,
description: `*Jawaban:* ${answer}`,
rowId: "row" + i
});
}
const sections = [{ title: `${conn.user.name} Brainly Command`, rows: data }]
const button = {
buttonText: 'Lihat jawaban',
description: "Jawaban kamu sudah ada ditemukan\n\nSilahkan klik tombol dibawah ya😁",
sections: sections,
listType: 1
}
conn.sendMessage(senderNumber, button, MessageType.listMessage, { quoted: message });
}).catch(err => {
conn.sendMessage(senderNumber, "Maaf terjadi kesalahan kak Y^Y)", MessageType.text, { quoted: message });
console.log(err);
});
break;
}
case `quotes`: {
const quotes = quotesList[Math.floor(Math.random() * quotesList.length)];
const text = `_"${quotes.quote}"_\n\n - ${quotes.by}`;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `randomfact`:
case `fact`: {
const fact = factList[Math.floor(Math.random() * factList.length)];
const text = `_${fact}_`
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `gtts`:
case `tts`:
case `text2sound`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, {quoted: message})
break;
}
case `wikipedia`:
case `wiki`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, { quoted: message })
break;
}
case `textsticker`:
case `textstiker`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, { quoted: message })
break;
}
case `gifsticker`:
case 'gifstiker': {
if (quotedMessage) {
message.message = quotedMessage;
}
if (!message.message.videoMessage || message.message.videoMessage.mimetype != "video/mp4") {
conn.sendMessage(senderNumber, "Gif atau videonya mana ya🤔", MessageType.text, {
quoted: message
});
break;
}
if (message.message.videoMessage.seconds > 8) {
conn.sendMessage(senderNumber, "Hmm... maksimal 8 detik kak maaf ya 🥺", MessageType.text, {
quoted: message
});
break;
}
const imagePath = await conn.downloadAndSaveMediaMessage(message, Math.floor(Math.random() * 1000000));
const sticker = new WSF.Sticker("./" + imagePath, {
animated: true,
pack: "Sticker",
author: stickerParameter
});
await sticker.build();
fs.unlinkSync(imagePath);
const bufferImage = await sticker.get();
conn.sendMessage(senderNumber, bufferImage, MessageType.sticker, {
quoted: message
});
break;
}
case `giftextsticker`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, { quoted: message })
}
case `math`: {
let tingkat = parameter.split(" ")[0];
let a = Math.floor(Math.random() * 101);
let b = Math.floor(Math.random() * 101);
let answer = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2))
console.log('hasilnya adalah: ' + answer);
const msg = await conn.sendMessage(senderNumber, `diketahui sebuah segitiga siku-siku dengan alas = ${a} dan tinggi = ${b}, tentukan sisi miringnya\n\nbalas pesan ini untuk menjawab`, MessageType.text, {
quoted: message
});
questionAnswer[msg.key.id] = parseInt(answer.toString())
console.log(questionAnswer[msg.key.id]);
setTimeout(() => {
if (questionAnswer[msg.key.id]) {
conn.sendMessage(senderNumber, `ups waktu habis jawabannya adalah *${hasil}*`, MessageType.text, {
quoted: msg
});
delete questionAnswer[msg.key.id];
}
}, 600 * 1000)
break;
}
case `stickernobg`:
case `stikernobg`:
case `snobg`: {
conn.sendMessage(senderNumber, "Mohon maaf fitur ini sedang dalam perbaikan", MessageType.text, {quoted: message})
// if (quotedMessage) {
// message.message = quotedMessage;
// }
// if (!message.message.imageMessage || message.message.imageMessage.mimetype != "image/jpeg") {
// conn.sendMessage(senderNumber, "Aduh gambarnya mana ya kak?, pastikan ada gambarnya atau reply sebuah gambar ya kak😉", MessageType.text, {
// quoted: message
// });
// break;
// }
// conn.sendMessage(senderNumber, 'Sedang di proses sabar ya kak. \n\ndiperikarakan sekitar 1 menit akan selesai maaf ya kak.', MessageType.text);
// const imagePath = await conn.downloadAndSaveMediaMessage(message);
// let output = Math.floor(Math.random() * 1000000);
// let outputPath = output.toString().concat("", ".png");
// const settings = {
// url: "https://api.clickmajic.com/v1/remove-background",
// sourceImagePath: imagePath,
// outputImagePath: outputPath
// };
// request.post(
// {
// url: settings.url,
// formData: { sourceFile: fs.createReadStream(settings.sourceImagePath), api_key: "da91f1a209fe88c68ad4cf2f571d4ed0" },
// encoding: null,
// },
// function (error, response, body) {
// if (error) { console.log(error); return; }
// if (response.statusCode != 200) { console.log(body.toString('utf8')); return; }
// fs.writeFileSync(settings.outputImagePath, body);
// }
// );
// const sticker = new WSF.Sticker(outputPath, {
// crop: false,
// pack: "sticker",
// author: stickerParameter
// });
// await sticker.build();
// const bufferImage = await sticker.get();
// conn.sendMessage(senderNumber, bufferImage, MessageType.sticker, {
// quoted: message
// });
// fs.unlinkSync(imagePath)
// fs.unlinkSync(outputPath);
// break;
break;
}
case `bplanet`: {
if (quotedMessage) message.message = quotedMessage
if (!!parameter) {
var [alias, ...text] = parameter.split` `
text = text.join` `
conn['sendMessage'](senderNumber, bahasa_planet(text, alias), 'conversation', {
quoted: message
})
} else {
var contoh = 'Inputnya salah kak 😅\n\nformat: !bplanet <alias> <text>\ncontoh: !bplanet g kamu lagi ngapain?'
conn['sendMessage'](senderNumber, contoh, 'conversation', {
quoted: message
})
}
break;
}
case `lirik`:
case `lyrics`: {
if (!parameter) {
conn.sendMessage(senderNumber, "Kok lagunya nggak ada sih kak 🥺, silahkan diulangi ya", MessageType.text, {
quoted: message
});
break;
}
const searches = await Client.songs.search(parameter);
const firstSong = searches[0]
if (!firstSong) {
conn.sendMessage(senderNumber, `maaf kami tidak bisa menemukan lirik dari *${parameter}*😭 silahkan coba lagu yang lain`, MessageType.text, {
quoted: message
});
} else {
const lyrics = await firstSong.lyrics();
const text = `lirik lagu *${firstSong.fullTitle}*\n\n${lyrics}`
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
}
break;
}
case `gempa`: {
const model = ['tr:nth-child(1) td'];
fetch('https://www.bmkg.go.id/gempabumi/gempabumi-terkini.bmkg').then((res) => res.text()).then((body) => {
let result = scrapy.extract(body, model);
let waktu = result[1] || "Tidak ada data";
let lintang = result[2] || "Tidak ada data";
let bujur = result[3] || "Tidak ada data";
let magnitudo = result[4] || "Tidak ada data";
let kedalaman = result[5] || "Tidak ada data";
let lokasi = result[6] || "Tidak ada data";
const text = `informasi gempa terbaru:\n\nWaktu: *${waktu}*\nBujur: *${bujur}*\nLintang: *${lintang}*\nMagnitudo: *${magnitudo}*\nKedalaman: *${kedalaman}*\nLokasi: *${lokasi}*`;
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
});
break;
}
case `ytmp3`: {
if (!parameter) {
conn.sendMessage(senderNumber, "Link nya mana 😭", MessageType.text, {
quoted: message
});
break;
}
const url = 'https://www.yt-download.org/api/button/mp3/';
if (ytregex.test(parameter)) {
var match = parameter.match(ytregex);
var result = (match && match[7].length == 11) ? match[7] : false;
var links = url + result;
if (ytregex.test(parameter)) {
conn.sendMessage(senderNumber, "Tunggu sebentar ya :3", MessageType.text, {
quoted: message
});
var match = parameter.match(ytregex);
var result = (match && match[7].length == 11) ? match[7] : false;
var links = 'https://freerestapi.herokuapp.com/api/ytmp3?url=https://www.youtube.com/watch?v=' + result;
request.get(links, { json: true }, (error, response, body) => {
if (!error || response.statusCode == 200) {
conn.sendMessage(senderNumber, `Audio kamu sudah siap di download\n*klik baca selengkanya sebelum klik link*\n\nJudul: *${body.title}*\nlink: ${body.url}`, MessageType.text, { quoted: message })
} else {
conn.sendMessage(senderNumber, "Maaf video yang kamu minta tidak bisa di download 😭", MessageType.text, { quoted: message });
}
})
}
} else {
conn.sendMessage(senderNumber, "Sepertinya link yang kamu masukkan salah, silahkan coba link lainnya ya.", MessageType.text, {
quoted: message
});
}
break;
}
case `tl`:
case `translate`: {
if (!parameter) {
conn.sendMessage(senderNumber, "Mau translate apa ya kak?", MessageType.text, {
quoted: message
})
} else {
const language = parameter.split(" ")[0];
const text = parameter.split(" ").splice(1).join(" ");
if (teslang.isSupported(language)) {
translate(text, {
to: language
}).then(res => {
let result = res;
let texts = `*${result}*`;
conn.sendMessage(senderNumber, texts, MessageType.text, {
quoted: message
});
}).catch(err => {
console.error(err);
});
} else {
const buttons = [{
buttonId: 'id1',
buttonText: {
displayText: '!kodebahasa',
},
type: 1
}]
const buttonMessage = {
contentText: "Maaf kode bahasa salah atau mungkin kamu lupa memasukkan kode bahasa.",
footerText: 'klik untuk mengetahui kode bahasa',
buttons: buttons,
headerType: 1
}
conn.sendMessage(senderNumber, buttonMessage, MessageType.buttonsMessage);
}
}
break;
}
case `kodebahasa`: {
const text = fs.readFileSync("./config/lang.txt", 'utf-8');
conn.sendMessage(senderNumber, text, MessageType.text, {
quoted: message
});
break;
}
case `yt`: {
if (!parameter) {
conn.sendMessage(senderNumber, "Link nya mana 😭", MessageType.text, {
});
break;
}
if (ytregex.test(parameter)) {
conn.sendMessage(senderNumber, "Tunggu sebentar ya :3", MessageType.text, {
quoted: message
});
var match = parameter.match(ytregex);
var result = (match && match[7].length == 11) ? match[7] : false;
var links = 'https://freerestapi.herokuapp.com/api/ytmp4?url=https://www.youtube.com/watch?v=' + result;
request.get(links, { json: true }, (error, response, body) => {
if (!error || response.statusCode == 200) {
conn.sendMessage(senderNumber, `Video kamu sudah siap di download\n\nJudul: *${body.title}*\nlink: ${body.url}`, MessageType.text, { quoted: message })
} else {
conn.sendMessage(senderNumber, "Maaf video yang kamu minta tidak bisa di download 😭", MessageType.text, { quoted: message });
}
})
} else {
conn.sendMessage(senderNumber, "Sepertinya link yang kamu masukkan salah, silahkan coba link lainnya ya.", MessageType.text, {
quoted: message
});
}
break;
}
default: {
if (quotedMessage && questionAnswer[quotedMessageContext.stanzaId] && textMessage) {
console.log(quotedMessage)
console.log(parseInt(textMessage))
const answer = questionAnswer[quotedMessageContext.stanzaId];
console.log(answer);
if (answer == parseInt(textMessage)) {
conn.sendMessage(senderNumber, "Mantap Jiwa Jawaban kamu benar 😆🎊🎉", MessageType.text, {
quoted: message
});
delete questionAnswer[quotedMessageContext.stanzaId];
} else {
conn.sendMessage(senderNumber, "Ups salah, coba lagi ya.", MessageType.text, {
quoted: message
})
}
}
}
}
}